OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #if defined(WEBRTC_POSIX) | 10 #if defined(WEBRTC_POSIX) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 const rtc::PacketTime& packet_time) { | 188 const rtc::PacketTime& packet_time) { |
189 turn_packets_.push_back(rtc::Buffer(data, size)); | 189 turn_packets_.push_back(rtc::Buffer(data, size)); |
190 } | 190 } |
191 void OnUdpPortComplete(Port* port) { | 191 void OnUdpPortComplete(Port* port) { |
192 udp_ready_ = true; | 192 udp_ready_ = true; |
193 } | 193 } |
194 void OnUdpReadPacket(Connection* conn, const char* data, size_t size, | 194 void OnUdpReadPacket(Connection* conn, const char* data, size_t size, |
195 const rtc::PacketTime& packet_time) { | 195 const rtc::PacketTime& packet_time) { |
196 udp_packets_.push_back(rtc::Buffer(data, size)); | 196 udp_packets_.push_back(rtc::Buffer(data, size)); |
197 } | 197 } |
198 void OnConnectionDestroyed(Connection* conn) { connection_destroyed_ = true; } | |
199 void OnSocketReadPacket(rtc::AsyncPacketSocket* socket, | 198 void OnSocketReadPacket(rtc::AsyncPacketSocket* socket, |
200 const char* data, size_t size, | 199 const char* data, size_t size, |
201 const rtc::SocketAddress& remote_addr, | 200 const rtc::SocketAddress& remote_addr, |
202 const rtc::PacketTime& packet_time) { | 201 const rtc::PacketTime& packet_time) { |
203 turn_port_->HandleIncomingPacket(socket, data, size, remote_addr, | 202 turn_port_->HandleIncomingPacket(socket, data, size, remote_addr, |
204 packet_time); | 203 packet_time); |
205 } | 204 } |
206 rtc::AsyncSocket* CreateServerSocket(const SocketAddress addr) { | 205 rtc::AsyncSocket* CreateServerSocket(const SocketAddress addr) { |
207 rtc::AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_STREAM); | 206 rtc::AsyncSocket* socket = ss_->CreateAsyncSocket(SOCK_STREAM); |
208 EXPECT_GE(socket->Bind(addr), 0); | 207 EXPECT_GE(socket->Bind(addr), 0); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 &TurnPortTest::OnTurnPortComplete); | 274 &TurnPortTest::OnTurnPortComplete); |
276 turn_port_->SignalPortError.connect(this, | 275 turn_port_->SignalPortError.connect(this, |
277 &TurnPortTest::OnTurnPortError); | 276 &TurnPortTest::OnTurnPortError); |
278 turn_port_->SignalUnknownAddress.connect(this, | 277 turn_port_->SignalUnknownAddress.connect(this, |
279 &TurnPortTest::OnTurnUnknownAddress); | 278 &TurnPortTest::OnTurnUnknownAddress); |
280 turn_port_->SignalCreatePermissionResult.connect(this, | 279 turn_port_->SignalCreatePermissionResult.connect(this, |
281 &TurnPortTest::OnTurnCreatePermissionResult); | 280 &TurnPortTest::OnTurnCreatePermissionResult); |
282 turn_port_->SignalTurnRefreshResult.connect( | 281 turn_port_->SignalTurnRefreshResult.connect( |
283 this, &TurnPortTest::OnTurnRefreshResult); | 282 this, &TurnPortTest::OnTurnRefreshResult); |
284 } | 283 } |
285 void ConnectConnectionDestroyedSignal(Connection* conn) { | |
286 conn->SignalDestroyed.connect(this, &TurnPortTest::OnConnectionDestroyed); | |
287 } | |
288 | 284 |
289 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); } | 285 void CreateUdpPort() { CreateUdpPort(kLocalAddr2); } |
290 | 286 |
291 void CreateUdpPort(const SocketAddress& address) { | 287 void CreateUdpPort(const SocketAddress& address) { |
292 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, | 288 udp_port_.reset(UDPPort::Create(main_, &socket_factory_, &network_, |
293 address.ipaddr(), 0, 0, kIceUfrag2, | 289 address.ipaddr(), 0, 0, kIceUfrag2, |
294 kIcePwd2, std::string(), false)); | 290 kIcePwd2, std::string(), false)); |
295 // UDP port will be controlled. | 291 // UDP port will be controlled. |
296 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED); | 292 udp_port_->SetIceRole(cricket::ICEROLE_CONTROLLED); |
297 udp_port_->SignalPortComplete.connect( | 293 udp_port_->SignalPortComplete.connect( |
298 this, &TurnPortTest::OnUdpPortComplete); | 294 this, &TurnPortTest::OnUdpPortComplete); |
299 } | 295 } |
300 | 296 |
301 void PrepareTurnAndUdpPorts() { | 297 void PrepareTurnAndUdpPorts() { |
302 // turn_port_ should have been created. | 298 // turn_port_ should have been created. |
303 ASSERT_TRUE(turn_port_ != nullptr); | 299 ASSERT_TRUE(turn_port_ != nullptr); |
304 turn_port_->PrepareAddress(); | 300 turn_port_->PrepareAddress(); |
305 ASSERT_TRUE_WAIT(turn_ready_, kTimeout); | 301 ASSERT_TRUE_WAIT(turn_ready_, kTimeout); |
306 | 302 |
307 CreateUdpPort(); | 303 CreateUdpPort(); |
308 udp_port_->PrepareAddress(); | 304 udp_port_->PrepareAddress(); |
309 ASSERT_TRUE_WAIT(udp_ready_, kTimeout); | 305 ASSERT_TRUE_WAIT(udp_ready_, kTimeout); |
310 } | 306 } |
311 | 307 |
312 bool CheckConnectionDestroyed() { | 308 bool CheckConnectionFailedAndPruned(Connection* conn) { |
313 turn_port_->FlushRequests(cricket::kAllRequests); | 309 return conn && !conn->active() && conn->state() == Connection::STATE_FAILED; |
314 rtc::Thread::Current()->ProcessMessages(50); | 310 } |
315 return connection_destroyed_; | 311 |
| 312 // Checks that |turn_port_| has a nonempty set of connections and they are all |
| 313 // failed and pruned. |
| 314 bool CheckAllConnectionsFailedAndPruned() { |
| 315 auto& connections = turn_port_->connections(); |
| 316 if (connections.empty()) { |
| 317 return false; |
| 318 } |
| 319 for (auto kv : connections) { |
| 320 if (!CheckConnectionFailedAndPruned(kv.second)) { |
| 321 return false; |
| 322 } |
| 323 } |
| 324 return true; |
316 } | 325 } |
317 | 326 |
318 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) { | 327 void TestTurnAlternateServer(cricket::ProtocolType protocol_type) { |
319 std::vector<rtc::SocketAddress> redirect_addresses; | 328 std::vector<rtc::SocketAddress> redirect_addresses; |
320 redirect_addresses.push_back(kTurnAlternateIntAddr); | 329 redirect_addresses.push_back(kTurnAlternateIntAddr); |
321 | 330 |
322 cricket::TestTurnRedirector redirector(redirect_addresses); | 331 cricket::TestTurnRedirector redirector(redirect_addresses); |
323 | 332 |
324 turn_server_.AddInternalSocket(kTurnIntAddr, protocol_type); | 333 turn_server_.AddInternalSocket(kTurnIntAddr, protocol_type); |
325 turn_server_.AddInternalSocket(kTurnAlternateIntAddr, protocol_type); | 334 turn_server_.AddInternalSocket(kTurnAlternateIntAddr, protocol_type); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 cricket::TestTurnServer turn_server_; | 526 cricket::TestTurnServer turn_server_; |
518 std::unique_ptr<TurnPort> turn_port_; | 527 std::unique_ptr<TurnPort> turn_port_; |
519 std::unique_ptr<UDPPort> udp_port_; | 528 std::unique_ptr<UDPPort> udp_port_; |
520 bool turn_ready_; | 529 bool turn_ready_; |
521 bool turn_error_; | 530 bool turn_error_; |
522 bool turn_unknown_address_; | 531 bool turn_unknown_address_; |
523 bool turn_create_permission_success_; | 532 bool turn_create_permission_success_; |
524 bool udp_ready_; | 533 bool udp_ready_; |
525 bool test_finish_; | 534 bool test_finish_; |
526 bool turn_refresh_success_ = false; | 535 bool turn_refresh_success_ = false; |
527 bool connection_destroyed_ = false; | |
528 std::vector<rtc::Buffer> turn_packets_; | 536 std::vector<rtc::Buffer> turn_packets_; |
529 std::vector<rtc::Buffer> udp_packets_; | 537 std::vector<rtc::Buffer> udp_packets_; |
530 rtc::PacketOptions options; | 538 rtc::PacketOptions options; |
531 }; | 539 }; |
532 | 540 |
533 // Do a normal TURN allocation. | 541 // Do a normal TURN allocation. |
534 TEST_F(TurnPortTest, TestTurnAllocate) { | 542 TEST_F(TurnPortTest, TestTurnAllocate) { |
535 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 543 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
536 EXPECT_EQ(0, turn_port_->SetOption(rtc::Socket::OPT_SNDBUF, 10*1024)); | 544 EXPECT_EQ(0, turn_port_->SetOption(rtc::Socket::OPT_SNDBUF, 10*1024)); |
537 turn_port_->PrepareAddress(); | 545 turn_port_->PrepareAddress(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 // Verifies that the new port has the same address. | 734 // Verifies that the new port has the same address. |
727 EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress()); | 735 EXPECT_EQ(first_addr, turn_port_->socket()->GetLocalAddress()); |
728 | 736 |
729 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 737 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
730 | 738 |
731 // Verifies that the new port has a different address now. | 739 // Verifies that the new port has a different address now. |
732 EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress()); | 740 EXPECT_NE(first_addr, turn_port_->socket()->GetLocalAddress()); |
733 } | 741 } |
734 | 742 |
735 TEST_F(TurnPortTest, TestRefreshRequestGetsErrorResponse) { | 743 TEST_F(TurnPortTest, TestRefreshRequestGetsErrorResponse) { |
| 744 rtc::ScopedFakeClock clock; |
736 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 745 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
737 PrepareTurnAndUdpPorts(); | 746 PrepareTurnAndUdpPorts(); |
738 turn_port_->CreateConnection(udp_port_->Candidates()[0], | 747 turn_port_->CreateConnection(udp_port_->Candidates()[0], |
739 Port::ORIGIN_MESSAGE); | 748 Port::ORIGIN_MESSAGE); |
740 // Set bad credentials. | 749 // Set bad credentials. |
741 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd"); | 750 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd"); |
742 turn_port_->set_credentials(bad_credentials); | 751 turn_port_->set_credentials(bad_credentials); |
743 turn_refresh_success_ = false; | 752 turn_refresh_success_ = false; |
744 // This sends out the first RefreshRequest with correct credentials. | 753 // This sends out the first RefreshRequest with correct credentials. |
745 // When this succeeds, it will schedule a new RefreshRequest with the bad | 754 // When this succeeds, it will schedule a new RefreshRequest with the bad |
746 // credential. | 755 // credential. |
747 turn_port_->FlushRequests(cricket::TURN_REFRESH_REQUEST); | 756 turn_port_->FlushRequests(cricket::TURN_REFRESH_REQUEST); |
748 EXPECT_TRUE_WAIT(turn_refresh_success_, kTimeout); | 757 EXPECT_TRUE_SIMULATED_WAIT(turn_refresh_success_, kTimeout, clock); |
749 // Flush it again, it will receive a bad response. | 758 // Flush it again, it will receive a bad response. |
750 turn_port_->FlushRequests(cricket::TURN_REFRESH_REQUEST); | 759 turn_port_->FlushRequests(cricket::TURN_REFRESH_REQUEST); |
751 EXPECT_TRUE_WAIT(!turn_refresh_success_, kTimeout); | 760 EXPECT_TRUE_SIMULATED_WAIT(!turn_refresh_success_, kTimeout, clock); |
752 EXPECT_TRUE_WAIT(!turn_port_->connected(), kTimeout); | 761 EXPECT_TRUE_SIMULATED_WAIT(!turn_port_->connected(), kTimeout, clock); |
753 EXPECT_TRUE_WAIT(turn_port_->connections().empty(), kTimeout); | 762 EXPECT_TRUE_SIMULATED_WAIT(CheckAllConnectionsFailedAndPruned(), kTimeout, |
754 EXPECT_FALSE(turn_port_->HasRequests()); | 763 clock); |
| 764 EXPECT_TRUE_SIMULATED_WAIT(!turn_port_->HasRequests(), kTimeout, clock); |
755 } | 765 } |
756 | 766 |
757 // Test that TurnPort will not handle any incoming packets once it has been | 767 // Test that TurnPort will not handle any incoming packets once it has been |
758 // closed. | 768 // closed. |
759 TEST_F(TurnPortTest, TestStopProcessingPacketsAfterClosed) { | 769 TEST_F(TurnPortTest, TestStopProcessingPacketsAfterClosed) { |
760 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 770 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
761 PrepareTurnAndUdpPorts(); | 771 PrepareTurnAndUdpPorts(); |
762 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], | 772 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], |
763 Port::ORIGIN_MESSAGE); | 773 Port::ORIGIN_MESSAGE); |
764 Connection* conn2 = udp_port_->CreateConnection(turn_port_->Candidates()[0], | 774 Connection* conn2 = udp_port_->CreateConnection(turn_port_->Candidates()[0], |
(...skipping 24 matching lines...) Expand all Loading... |
789 Port::ORIGIN_MESSAGE); | 799 Port::ORIGIN_MESSAGE); |
790 ASSERT_TRUE(conn1 != NULL); | 800 ASSERT_TRUE(conn1 != NULL); |
791 | 801 |
792 // Close the socket and create a connection again. | 802 // Close the socket and create a connection again. |
793 turn_port_->OnSocketClose(turn_port_->socket(), 1); | 803 turn_port_->OnSocketClose(turn_port_->socket(), 1); |
794 conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], | 804 conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], |
795 Port::ORIGIN_MESSAGE); | 805 Port::ORIGIN_MESSAGE); |
796 ASSERT_TRUE(conn1 == NULL); | 806 ASSERT_TRUE(conn1 == NULL); |
797 } | 807 } |
798 | 808 |
| 809 // Tests that when a TCP socket is closed, the respective TURN connection will |
| 810 // be destroyed. |
| 811 TEST_F(TurnPortTest, TestSocketCloseWillDestroyConnection) { |
| 812 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
| 813 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); |
| 814 PrepareTurnAndUdpPorts(); |
| 815 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0], |
| 816 Port::ORIGIN_MESSAGE); |
| 817 EXPECT_NE(nullptr, conn); |
| 818 EXPECT_TRUE(!turn_port_->connections().empty()); |
| 819 turn_port_->socket()->SignalClose(turn_port_->socket(), 1); |
| 820 EXPECT_TRUE_WAIT(turn_port_->connections().empty(), kTimeout); |
| 821 } |
| 822 |
799 // Test try-alternate-server feature. | 823 // Test try-alternate-server feature. |
800 TEST_F(TurnPortTest, TestTurnAlternateServerUDP) { | 824 TEST_F(TurnPortTest, TestTurnAlternateServerUDP) { |
801 TestTurnAlternateServer(cricket::PROTO_UDP); | 825 TestTurnAlternateServer(cricket::PROTO_UDP); |
802 } | 826 } |
803 | 827 |
804 TEST_F(TurnPortTest, TestTurnAlternateServerTCP) { | 828 TEST_F(TurnPortTest, TestTurnAlternateServerTCP) { |
805 TestTurnAlternateServer(cricket::PROTO_TCP); | 829 TestTurnAlternateServer(cricket::PROTO_TCP); |
806 } | 830 } |
807 | 831 |
808 // Test that we fail when we redirect to an address different from | 832 // Test that we fail when we redirect to an address different from |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 | 916 |
893 // Test that CreatePermissionRequest will be scheduled after the success | 917 // Test that CreatePermissionRequest will be scheduled after the success |
894 // of the first create permission request and the request will get an | 918 // of the first create permission request and the request will get an |
895 // ErrorResponse if the ufrag and pwd are incorrect. | 919 // ErrorResponse if the ufrag and pwd are incorrect. |
896 TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) { | 920 TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) { |
897 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 921 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
898 PrepareTurnAndUdpPorts(); | 922 PrepareTurnAndUdpPorts(); |
899 | 923 |
900 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0], | 924 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0], |
901 Port::ORIGIN_MESSAGE); | 925 Port::ORIGIN_MESSAGE); |
902 ConnectConnectionDestroyedSignal(conn); | |
903 ASSERT_TRUE(conn != NULL); | 926 ASSERT_TRUE(conn != NULL); |
904 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); | 927 EXPECT_TRUE_WAIT(turn_create_permission_success_, kTimeout); |
905 turn_create_permission_success_ = false; | 928 turn_create_permission_success_ = false; |
906 // A create-permission-request should be pending. | 929 // A create-permission-request should be pending. |
907 // After the next create-permission-response is received, it will schedule | 930 // After the next create-permission-response is received, it will schedule |
908 // another request with bad_ufrag and bad_pwd. | 931 // another request with bad_ufrag and bad_pwd. |
909 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd"); | 932 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd"); |
910 turn_port_->set_credentials(bad_credentials); | 933 turn_port_->set_credentials(bad_credentials); |
911 turn_port_->FlushRequests(cricket::kAllRequests); | 934 turn_port_->FlushRequests(cricket::kAllRequests); |
912 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); | 935 EXPECT_TRUE_WAIT(turn_create_permission_success_, kTimeout); |
913 // Flush the requests again; the create-permission-request will fail. | 936 // Flush the requests again; the create-permission-request will fail. |
914 turn_port_->FlushRequests(cricket::kAllRequests); | 937 turn_port_->FlushRequests(cricket::kAllRequests); |
915 EXPECT_TRUE_WAIT(!turn_create_permission_success_, kTimeout); | 938 EXPECT_TRUE_WAIT(!turn_create_permission_success_, kTimeout); |
916 EXPECT_TRUE_WAIT(connection_destroyed_, kTimeout); | 939 EXPECT_TRUE_WAIT(CheckConnectionFailedAndPruned(conn), kTimeout); |
917 } | 940 } |
918 | 941 |
919 TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) { | 942 TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) { |
| 943 rtc::ScopedFakeClock clock; |
920 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 944 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
921 PrepareTurnAndUdpPorts(); | 945 PrepareTurnAndUdpPorts(); |
922 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], | 946 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], |
923 Port::ORIGIN_MESSAGE); | 947 Port::ORIGIN_MESSAGE); |
924 ASSERT_TRUE(conn1 != nullptr); | 948 ASSERT_TRUE(conn1 != nullptr); |
925 Connection* conn2 = udp_port_->CreateConnection(turn_port_->Candidates()[0], | 949 Connection* conn2 = udp_port_->CreateConnection(turn_port_->Candidates()[0], |
926 Port::ORIGIN_MESSAGE); | 950 Port::ORIGIN_MESSAGE); |
| 951 |
927 ASSERT_TRUE(conn2 != nullptr); | 952 ASSERT_TRUE(conn2 != nullptr); |
928 ConnectConnectionDestroyedSignal(conn1); | |
929 conn1->Ping(0); | 953 conn1->Ping(0); |
930 ASSERT_TRUE_WAIT(conn1->writable(), kTimeout); | 954 EXPECT_TRUE_SIMULATED_WAIT(conn1->writable(), kTimeout, clock); |
| 955 bool success = |
| 956 turn_port_->SetEntryChannelId(udp_port_->Candidates()[0].address(), -1); |
| 957 ASSERT_TRUE(success); |
931 | 958 |
932 std::string data = "ABC"; | 959 std::string data = "ABC"; |
933 conn1->Send(data.data(), data.length(), options); | 960 conn1->Send(data.data(), data.length(), options); |
934 bool success = | 961 |
935 turn_port_->SetEntryChannelId(udp_port_->Candidates()[0].address(), -1); | 962 EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn1), kTimeout, |
936 ASSERT_TRUE(success); | 963 clock); |
937 // Next time when the binding request is sent, it will get an ErrorResponse. | 964 // Verify that no packet can be sent after a bind request error. |
938 EXPECT_TRUE_WAIT(CheckConnectionDestroyed(), kTimeout); | 965 conn2->SignalReadPacket.connect(static_cast<TurnPortTest*>(this), |
| 966 &TurnPortTest::OnUdpReadPacket); |
| 967 conn1->Send(data.data(), data.length(), options); |
| 968 SIMULATED_WAIT(!udp_packets_.empty(), kTimeout, clock); |
| 969 EXPECT_TRUE(udp_packets_.empty()); |
939 } | 970 } |
940 | 971 |
941 // Do a TURN allocation, establish a UDP connection, and send some data. | 972 // Do a TURN allocation, establish a UDP connection, and send some data. |
942 TEST_F(TurnPortTest, TestTurnSendDataTurnUdpToUdp) { | 973 TEST_F(TurnPortTest, TestTurnSendDataTurnUdpToUdp) { |
943 // Create ports and prepare addresses. | 974 // Create ports and prepare addresses. |
944 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 975 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
945 TestTurnSendData(); | 976 TestTurnSendData(); |
946 EXPECT_EQ(cricket::UDP_PROTOCOL_NAME, | 977 EXPECT_EQ(cricket::UDP_PROTOCOL_NAME, |
947 turn_port_->Candidates()[0].relay_protocol()); | 978 turn_port_->Candidates()[0].relay_protocol()); |
948 } | 979 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 kTurnUdpProtoAddr, kTestOrigin); | 1019 kTurnUdpProtoAddr, kTestOrigin); |
989 turn_port_->PrepareAddress(); | 1020 turn_port_->PrepareAddress(); |
990 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 1021 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
991 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); | 1022 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); |
992 SocketAddress local_address = turn_port_->GetLocalAddress(); | 1023 SocketAddress local_address = turn_port_->GetLocalAddress(); |
993 ASSERT_TRUE(turn_server_.FindAllocation(local_address) != NULL); | 1024 ASSERT_TRUE(turn_server_.FindAllocation(local_address) != NULL); |
994 EXPECT_EQ(kTestOrigin, turn_server_.FindAllocation(local_address)->origin()); | 1025 EXPECT_EQ(kTestOrigin, turn_server_.FindAllocation(local_address)->origin()); |
995 } | 1026 } |
996 | 1027 |
997 // Test that a CreatePermission failure will result in the connection being | 1028 // Test that a CreatePermission failure will result in the connection being |
998 // destroyed. | 1029 // pruned and failed. |
999 TEST_F(TurnPortTest, TestConnectionDestroyedOnCreatePermissionFailure) { | 1030 TEST_F(TurnPortTest, TestConnectionFaildAndPrunedOnCreatePermissionFailure) { |
| 1031 rtc::ScopedFakeClock clock; |
| 1032 SIMULATED_WAIT(false, 101, clock); |
1000 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 1033 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
1001 turn_server_.server()->set_reject_private_addresses(true); | 1034 turn_server_.server()->set_reject_private_addresses(true); |
1002 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); | 1035 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); |
1003 turn_port_->PrepareAddress(); | 1036 turn_port_->PrepareAddress(); |
1004 ASSERT_TRUE_WAIT(turn_ready_, kTimeout); | 1037 EXPECT_TRUE_SIMULATED_WAIT(turn_ready_, kTimeout, clock); |
1005 | 1038 |
1006 CreateUdpPort(SocketAddress("10.0.0.10", 0)); | 1039 CreateUdpPort(SocketAddress("10.0.0.10", 0)); |
1007 udp_port_->PrepareAddress(); | 1040 udp_port_->PrepareAddress(); |
1008 ASSERT_TRUE_WAIT(udp_ready_, kTimeout); | 1041 EXPECT_TRUE_SIMULATED_WAIT(udp_ready_, kTimeout, clock); |
1009 // Create a connection. | 1042 // Create a connection. |
1010 TestConnectionWrapper conn(turn_port_->CreateConnection( | 1043 TestConnectionWrapper conn(turn_port_->CreateConnection( |
1011 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE)); | 1044 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE)); |
1012 ASSERT_TRUE(conn.connection() != nullptr); | 1045 EXPECT_TRUE(conn.connection() != nullptr); |
1013 | 1046 |
1014 // Asynchronously, CreatePermission request should be sent and fail, closing | 1047 // Asynchronously, CreatePermission request should be sent and fail, which |
1015 // the connection. | 1048 // will make the connection pruned and failed. |
1016 EXPECT_TRUE_WAIT(conn.connection() == nullptr, kTimeout); | 1049 EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn.connection()), |
1017 EXPECT_FALSE(turn_create_permission_success_); | 1050 kTimeout, clock); |
| 1051 EXPECT_TRUE_SIMULATED_WAIT(!turn_create_permission_success_, kTimeout, clock); |
| 1052 // Check that the connection is not deleted asynchronously. |
| 1053 SIMULATED_WAIT(conn.connection() == nullptr, kTimeout, clock); |
| 1054 EXPECT_TRUE(conn.connection() != nullptr); |
1018 } | 1055 } |
1019 | 1056 |
1020 // Test that a TURN allocation is released when the port is closed. | 1057 // Test that a TURN allocation is released when the port is closed. |
1021 TEST_F(TurnPortTest, TestTurnReleaseAllocation) { | 1058 TEST_F(TurnPortTest, TestTurnReleaseAllocation) { |
1022 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 1059 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
1023 turn_port_->PrepareAddress(); | 1060 turn_port_->PrepareAddress(); |
1024 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 1061 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
1025 | 1062 |
1026 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); | 1063 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); |
1027 turn_port_.reset(); | 1064 turn_port_.reset(); |
(...skipping 29 matching lines...) Expand all Loading... |
1057 turn_port_->PrepareAddress(); | 1094 turn_port_->PrepareAddress(); |
1058 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); | 1095 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); |
1059 EXPECT_TRUE(turn_port_->Candidates().empty()); | 1096 EXPECT_TRUE(turn_port_->Candidates().empty()); |
1060 turn_port_.reset(); | 1097 turn_port_.reset(); |
1061 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); | 1098 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); |
1062 // Waiting for above message to be processed. | 1099 // Waiting for above message to be processed. |
1063 ASSERT_TRUE_WAIT(test_finish_, kTimeout); | 1100 ASSERT_TRUE_WAIT(test_finish_, kTimeout); |
1064 EXPECT_EQ(last_fd_count, GetFDCount()); | 1101 EXPECT_EQ(last_fd_count, GetFDCount()); |
1065 } | 1102 } |
1066 #endif | 1103 #endif |
OLD | NEW |