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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
887 TEST_F(TurnPortTest, TestTurnConnectionUsingOTUNonce) { | 897 TEST_F(TurnPortTest, TestTurnConnectionUsingOTUNonce) { |
888 turn_server_.set_enable_otu_nonce(true); | 898 turn_server_.set_enable_otu_nonce(true); |
889 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 899 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
890 TestTurnConnection(); | 900 TestTurnConnection(); |
891 } | 901 } |
892 | 902 |
893 // Test that CreatePermissionRequest will be scheduled after the success | 903 // Test that CreatePermissionRequest will be scheduled after the success |
894 // of the first create permission request and the request will get an | 904 // of the first create permission request and the request will get an |
895 // ErrorResponse if the ufrag and pwd are incorrect. | 905 // ErrorResponse if the ufrag and pwd are incorrect. |
896 TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) { | 906 TEST_F(TurnPortTest, TestRefreshCreatePermissionRequest) { |
907 rtc::ScopedFakeClock clock; | |
Taylor Brandstetter
2016/06/21 18:48:08
Why is the fake clock needed here and in the test
honghaiz3
2016/06/22 01:50:41
Removed using FakeClock here and below.
| |
897 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 908 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
898 PrepareTurnAndUdpPorts(); | 909 PrepareTurnAndUdpPorts(); |
899 | 910 |
900 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0], | 911 Connection* conn = turn_port_->CreateConnection(udp_port_->Candidates()[0], |
901 Port::ORIGIN_MESSAGE); | 912 Port::ORIGIN_MESSAGE); |
902 ConnectConnectionDestroyedSignal(conn); | |
903 ASSERT_TRUE(conn != NULL); | 913 ASSERT_TRUE(conn != NULL); |
904 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); | 914 EXPECT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kTimeout, clock); |
905 turn_create_permission_success_ = false; | 915 turn_create_permission_success_ = false; |
906 // A create-permission-request should be pending. | 916 // A create-permission-request should be pending. |
907 // After the next create-permission-response is received, it will schedule | 917 // After the next create-permission-response is received, it will schedule |
908 // another request with bad_ufrag and bad_pwd. | 918 // another request with bad_ufrag and bad_pwd. |
909 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd"); | 919 cricket::RelayCredentials bad_credentials("bad_user", "bad_pwd"); |
910 turn_port_->set_credentials(bad_credentials); | 920 turn_port_->set_credentials(bad_credentials); |
911 turn_port_->FlushRequests(cricket::kAllRequests); | 921 turn_port_->FlushRequests(cricket::kAllRequests); |
912 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout); | 922 EXPECT_TRUE_SIMULATED_WAIT(turn_create_permission_success_, kTimeout, clock); |
913 // Flush the requests again; the create-permission-request will fail. | 923 // Flush the requests again; the create-permission-request will fail. |
914 turn_port_->FlushRequests(cricket::kAllRequests); | 924 turn_port_->FlushRequests(cricket::kAllRequests); |
915 EXPECT_TRUE_WAIT(!turn_create_permission_success_, kTimeout); | 925 EXPECT_TRUE_SIMULATED_WAIT(!turn_create_permission_success_, kTimeout, clock); |
916 EXPECT_TRUE_WAIT(connection_destroyed_, kTimeout); | 926 EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn), kTimeout, |
927 clock); | |
917 } | 928 } |
918 | 929 |
919 TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) { | 930 TEST_F(TurnPortTest, TestChannelBindGetErrorResponse) { |
931 rtc::ScopedFakeClock clock; | |
920 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 932 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
921 PrepareTurnAndUdpPorts(); | 933 PrepareTurnAndUdpPorts(); |
922 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], | 934 Connection* conn1 = turn_port_->CreateConnection(udp_port_->Candidates()[0], |
923 Port::ORIGIN_MESSAGE); | 935 Port::ORIGIN_MESSAGE); |
924 ASSERT_TRUE(conn1 != nullptr); | 936 ASSERT_TRUE(conn1 != nullptr); |
925 Connection* conn2 = udp_port_->CreateConnection(turn_port_->Candidates()[0], | 937 Connection* conn2 = udp_port_->CreateConnection(turn_port_->Candidates()[0], |
926 Port::ORIGIN_MESSAGE); | 938 Port::ORIGIN_MESSAGE); |
927 ASSERT_TRUE(conn2 != nullptr); | 939 ASSERT_TRUE(conn2 != nullptr); |
928 ConnectConnectionDestroyedSignal(conn1); | |
929 conn1->Ping(0); | 940 conn1->Ping(0); |
930 ASSERT_TRUE_WAIT(conn1->writable(), kTimeout); | 941 EXPECT_TRUE_SIMULATED_WAIT(conn1->writable(), kTimeout, clock); |
931 | |
932 std::string data = "ABC"; | |
933 conn1->Send(data.data(), data.length(), options); | |
934 bool success = | 942 bool success = |
935 turn_port_->SetEntryChannelId(udp_port_->Candidates()[0].address(), -1); | 943 turn_port_->SetEntryChannelId(udp_port_->Candidates()[0].address(), -1); |
936 ASSERT_TRUE(success); | 944 ASSERT_TRUE(success); |
937 // Next time when the binding request is sent, it will get an ErrorResponse. | 945 std::string data = "ABC"; |
938 EXPECT_TRUE_WAIT(CheckConnectionDestroyed(), kTimeout); | 946 conn1->Send(data.data(), data.length(), options); |
Taylor Brandstetter
2016/06/21 18:48:08
Are there any EXPECTS that should be added for the
honghaiz3
2016/06/22 01:50:41
Added a test that future packets cannot be sent on
| |
947 | |
948 EXPECT_TRUE_SIMULATED_WAIT(CheckConnectionFailedAndPruned(conn1), kTimeout, | |
949 clock); | |
939 } | 950 } |
940 | 951 |
941 // Do a TURN allocation, establish a UDP connection, and send some data. | 952 // Do a TURN allocation, establish a UDP connection, and send some data. |
942 TEST_F(TurnPortTest, TestTurnSendDataTurnUdpToUdp) { | 953 TEST_F(TurnPortTest, TestTurnSendDataTurnUdpToUdp) { |
943 // Create ports and prepare addresses. | 954 // Create ports and prepare addresses. |
944 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 955 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
945 TestTurnSendData(); | 956 TestTurnSendData(); |
946 EXPECT_EQ(cricket::UDP_PROTOCOL_NAME, | 957 EXPECT_EQ(cricket::UDP_PROTOCOL_NAME, |
947 turn_port_->Candidates()[0].relay_protocol()); | 958 turn_port_->Candidates()[0].relay_protocol()); |
948 } | 959 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
988 kTurnUdpProtoAddr, kTestOrigin); | 999 kTurnUdpProtoAddr, kTestOrigin); |
989 turn_port_->PrepareAddress(); | 1000 turn_port_->PrepareAddress(); |
990 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 1001 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
991 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); | 1002 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); |
992 SocketAddress local_address = turn_port_->GetLocalAddress(); | 1003 SocketAddress local_address = turn_port_->GetLocalAddress(); |
993 ASSERT_TRUE(turn_server_.FindAllocation(local_address) != NULL); | 1004 ASSERT_TRUE(turn_server_.FindAllocation(local_address) != NULL); |
994 EXPECT_EQ(kTestOrigin, turn_server_.FindAllocation(local_address)->origin()); | 1005 EXPECT_EQ(kTestOrigin, turn_server_.FindAllocation(local_address)->origin()); |
995 } | 1006 } |
996 | 1007 |
997 // Test that a CreatePermission failure will result in the connection being | 1008 // Test that a CreatePermission failure will result in the connection being |
998 // destroyed. | 1009 // pruned and failed. |
999 TEST_F(TurnPortTest, TestConnectionDestroyedOnCreatePermissionFailure) { | 1010 // TODO(honghaiz): Investigate why the test fails with FakeClock. |
1011 TEST_F(TurnPortTest, TestConnectionFaildAndPredOnCreatePermissionFailure) { | |
Taylor Brandstetter
2016/06/21 18:48:08
"AndPred" should be "AndPruned"?
honghaiz3
2016/06/22 01:50:41
Done.
| |
1000 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 1012 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
1001 turn_server_.server()->set_reject_private_addresses(true); | 1013 turn_server_.server()->set_reject_private_addresses(true); |
1002 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); | 1014 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); |
1003 turn_port_->PrepareAddress(); | 1015 turn_port_->PrepareAddress(); |
1004 ASSERT_TRUE_WAIT(turn_ready_, kTimeout); | 1016 ASSERT_TRUE_WAIT(turn_ready_, kTimeout); |
1005 | 1017 |
1006 CreateUdpPort(SocketAddress("10.0.0.10", 0)); | 1018 CreateUdpPort(SocketAddress("10.0.0.10", 0)); |
1007 udp_port_->PrepareAddress(); | 1019 udp_port_->PrepareAddress(); |
1008 ASSERT_TRUE_WAIT(udp_ready_, kTimeout); | 1020 ASSERT_TRUE_WAIT(udp_ready_, kTimeout); |
1009 // Create a connection. | 1021 // Create a connection. |
1010 TestConnectionWrapper conn(turn_port_->CreateConnection( | 1022 TestConnectionWrapper conn(turn_port_->CreateConnection( |
1011 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE)); | 1023 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE)); |
1012 ASSERT_TRUE(conn.connection() != nullptr); | 1024 ASSERT_TRUE(conn.connection() != nullptr); |
1013 | 1025 |
1014 // Asynchronously, CreatePermission request should be sent and fail, closing | 1026 // Asynchronously, CreatePermission request should be sent and fail, which |
1015 // the connection. | 1027 // will make the connection pruned and failed. |
1016 EXPECT_TRUE_WAIT(conn.connection() == nullptr, kTimeout); | 1028 EXPECT_TRUE_WAIT(CheckConnectionFailedAndPruned(conn.connection()), kTimeout); |
1017 EXPECT_FALSE(turn_create_permission_success_); | 1029 EXPECT_TRUE_WAIT(!turn_create_permission_success_, kTimeout); |
1030 rtc::Thread::Current()->ProcessMessages(500); | |
Taylor Brandstetter
2016/06/21 18:48:08
Is the purpose of ProcessMessages(500) to make sur
honghaiz3
2016/06/22 01:50:41
Done. Fixing an issue in virtualsocketserver when
| |
1031 // Check that the connection is not deleted. | |
1032 EXPECT_TRUE(conn.connection() != nullptr); | |
1018 } | 1033 } |
1019 | 1034 |
1020 // Test that a TURN allocation is released when the port is closed. | 1035 // Test that a TURN allocation is released when the port is closed. |
1021 TEST_F(TurnPortTest, TestTurnReleaseAllocation) { | 1036 TEST_F(TurnPortTest, TestTurnReleaseAllocation) { |
1022 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); | 1037 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr); |
1023 turn_port_->PrepareAddress(); | 1038 turn_port_->PrepareAddress(); |
1024 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); | 1039 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); |
1025 | 1040 |
1026 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); | 1041 ASSERT_GT(turn_server_.server()->allocations().size(), 0U); |
1027 turn_port_.reset(); | 1042 turn_port_.reset(); |
(...skipping 29 matching lines...) Expand all Loading... | |
1057 turn_port_->PrepareAddress(); | 1072 turn_port_->PrepareAddress(); |
1058 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); | 1073 ASSERT_TRUE_WAIT(turn_error_, kResolverTimeout); |
1059 EXPECT_TRUE(turn_port_->Candidates().empty()); | 1074 EXPECT_TRUE(turn_port_->Candidates().empty()); |
1060 turn_port_.reset(); | 1075 turn_port_.reset(); |
1061 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); | 1076 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); |
1062 // Waiting for above message to be processed. | 1077 // Waiting for above message to be processed. |
1063 ASSERT_TRUE_WAIT(test_finish_, kTimeout); | 1078 ASSERT_TRUE_WAIT(test_finish_, kTimeout); |
1064 EXPECT_EQ(last_fd_count, GetFDCount()); | 1079 EXPECT_EQ(last_fd_count, GetFDCount()); |
1065 } | 1080 } |
1066 #endif | 1081 #endif |
OLD | NEW |