Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: webrtc/p2p/base/turnport_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698