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

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

Issue 1426673007: Do not delete the turn port entry right away when the respective connection is deleted. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 1 month 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 EXPECT_TRUE(conn1->receiving()); 378 EXPECT_TRUE(conn1->receiving());
379 EXPECT_TRUE(conn2->receiving()); 379 EXPECT_TRUE(conn2->receiving());
380 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state()); 380 EXPECT_EQ(Connection::STATE_WRITE_INIT, conn1->write_state());
381 381
382 // Send another ping from UDP to TURN. 382 // Send another ping from UDP to TURN.
383 conn1->Ping(0); 383 conn1->Ping(0);
384 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), kTimeout); 384 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), kTimeout);
385 EXPECT_TRUE(conn2->receiving()); 385 EXPECT_TRUE(conn2->receiving());
386 } 386 }
387 387
388 void TestDestroyTurnConnection() {
389 turn_port_->PrepareAddress();
390 ASSERT_TRUE_WAIT(turn_ready_, kTimeout);
391 // Create a remote UDP port
392 CreateUdpPort();
393 udp_port_->PrepareAddress();
394 ASSERT_TRUE_WAIT(udp_ready_, kTimeout);
395
396 // Create connections on both ends.
397 Connection* conn1 = udp_port_->CreateConnection(turn_port_->Candidates()[0],
398 Port::ORIGIN_MESSAGE);
399 Connection* conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
400 Port::ORIGIN_MESSAGE);
401 ASSERT_TRUE(conn2 != NULL);
402 ASSERT_TRUE_WAIT(turn_create_permission_success_, kTimeout);
403 // Make sure turn connection can receive.
404 conn1->Ping(0);
405 EXPECT_EQ_WAIT(Connection::STATE_WRITABLE, conn1->write_state(), kTimeout);
406 EXPECT_FALSE(turn_unknown_address_);
407
408 // Destroy the connection on the turn port. The TurnEntry is still
409 // there. So the turn port gets ping from unknown address if it is pinged.
410 conn2->Destroy();
411 conn1->Ping(0);
412 EXPECT_TRUE_WAIT(turn_unknown_address_, kTimeout);
413
414 // Flush all requests in the invoker to destroy the TurnEntry.
415 // Now the turn port cannot receive the ping.
416 turn_unknown_address_ = false;
417 turn_port_->invoker()->Flush(rtc::Thread::Current());
418 conn1->Ping(0);
419 rtc::Thread::Current()->ProcessMessages(500);
420 EXPECT_FALSE(turn_unknown_address_);
421
422 // If the connection is created again, it will start to receive pings.
423 conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
424 Port::ORIGIN_MESSAGE);
425 conn1->Ping(0);
426 EXPECT_TRUE_WAIT(conn2->receiving(), kTimeout);
427 EXPECT_FALSE(turn_unknown_address_);
428 }
429
388 void TestTurnSendData() { 430 void TestTurnSendData() {
389 turn_port_->PrepareAddress(); 431 turn_port_->PrepareAddress();
390 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 432 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
391 CreateUdpPort(); 433 CreateUdpPort();
392 udp_port_->PrepareAddress(); 434 udp_port_->PrepareAddress();
393 EXPECT_TRUE_WAIT(udp_ready_, kTimeout); 435 EXPECT_TRUE_WAIT(udp_ready_, kTimeout);
394 // Create connections and send pings. 436 // Create connections and send pings.
395 Connection* conn1 = turn_port_->CreateConnection( 437 Connection* conn1 = turn_port_->CreateConnection(
396 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE); 438 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE);
397 Connection* conn2 = udp_port_->CreateConnection( 439 Connection* conn2 = udp_port_->CreateConnection(
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 TestTurnConnection(); 729 TestTurnConnection();
688 } 730 }
689 731
690 // Test that we can establish a TCP connection with TURN server. 732 // Test that we can establish a TCP connection with TURN server.
691 TEST_F(TurnPortTest, TestTurnTcpConnection) { 733 TEST_F(TurnPortTest, TestTurnTcpConnection) {
692 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 734 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
693 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); 735 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
694 TestTurnConnection(); 736 TestTurnConnection();
695 } 737 }
696 738
739 // Test that if a connection on a TURN port is destroyed, the TURN port can
740 // still receive ping on that connection as if it is from an unknown address.
741 // If the connection is created again, it will be used to receive ping.
742 TEST_F(TurnPortTest, TestDestroyTurnConnection) {
743 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
744 TestDestroyTurnConnection();
745 }
746
747 // Similar to above, except that this test will use the shared socket.
748 TEST_F(TurnPortTest, TestDestroyTurnConnectionUsingSharedSocket) {
749 CreateSharedTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
750 TestDestroyTurnConnection();
751 }
752
697 // Test that we fail to create a connection when we want to use TLS over TCP. 753 // Test that we fail to create a connection when we want to use TLS over TCP.
698 // This test should be removed once we have TLS support. 754 // This test should be removed once we have TLS support.
699 TEST_F(TurnPortTest, TestTurnTlsTcpConnectionFails) { 755 TEST_F(TurnPortTest, TestTurnTlsTcpConnectionFails) {
700 cricket::ProtocolAddress secure_addr(kTurnTcpProtoAddr.address, 756 cricket::ProtocolAddress secure_addr(kTurnTcpProtoAddr.address,
701 kTurnTcpProtoAddr.proto, 757 kTurnTcpProtoAddr.proto,
702 true); 758 true);
703 CreateTurnPort(kTurnUsername, kTurnPassword, secure_addr); 759 CreateTurnPort(kTurnUsername, kTurnPassword, secure_addr);
704 turn_port_->PrepareAddress(); 760 turn_port_->PrepareAddress();
705 EXPECT_TRUE_WAIT(turn_error_, kTimeout); 761 EXPECT_TRUE_WAIT(turn_error_, kTimeout);
706 ASSERT_EQ(0U, turn_port_->Candidates().size()); 762 ASSERT_EQ(0U, turn_port_->Candidates().size());
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 turn_port_->PrepareAddress(); 885 turn_port_->PrepareAddress();
830 ASSERT_TRUE_WAIT(turn_error_, kTimeout); 886 ASSERT_TRUE_WAIT(turn_error_, kTimeout);
831 EXPECT_TRUE(turn_port_->Candidates().empty()); 887 EXPECT_TRUE(turn_port_->Candidates().empty());
832 turn_port_.reset(); 888 turn_port_.reset();
833 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); 889 rtc::Thread::Current()->Post(this, MSG_TESTFINISH);
834 // Waiting for above message to be processed. 890 // Waiting for above message to be processed.
835 ASSERT_TRUE_WAIT(test_finish_, kTimeout); 891 ASSERT_TRUE_WAIT(test_finish_, kTimeout);
836 EXPECT_EQ(last_fd_count, GetFDCount()); 892 EXPECT_EQ(last_fd_count, GetFDCount());
837 } 893 }
838 #endif 894 #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