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

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
« webrtc/p2p/base/turnport.cc ('K') | « 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 // Now 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 // If the connection is created again, it will start to receive pings.
415 turn_unknown_address_ = false;
416 conn2 = turn_port_->CreateConnection(udp_port_->Candidates()[0],
417 Port::ORIGIN_MESSAGE);
418 conn1->Ping(0);
419 EXPECT_TRUE_WAIT(conn2->receiving(), kTimeout);
420 EXPECT_FALSE(turn_unknown_address_);
421 // Check that the message posted by the invoker is deleted.
422 rtc::MessageList removed;
423 rtc::Thread::Current()->Clear(turn_port_->invoker(), rtc::MQID_ANY,
424 &removed);
425 EXPECT_TRUE(removed.empty());
426
427 // Now destroy conn2 and Flush the invoker. The turn port will not be able
428 // to receive the ping message.
429 turn_unknown_address_ = false;
430 conn1->set_receiving_timeout(400);
431 conn2->Destroy();
432 // Send the destroy message to the message queue.
433 rtc::Thread::Current()->ProcessMessages(0);
434 turn_port_->invoker()->Flush(rtc::Thread::Current());
435 // Ensure it is not receiving.
436 rtc::Thread::Current()->ProcessMessages(500);
pthatcher1 2015/11/11 01:08:41 This could end up being flaky. Could we use EXPEC
honghaiz3 2015/11/11 23:02:55 Done. Cann't use the EXPECT_TRUE_WAIT because we a
437 conn1->UpdateState(rtc::Time());
438 conn1->Ping(0);
439 rtc::Thread::Current()->ProcessMessages(100);
440 EXPECT_FALSE(conn1->receiving());
441 EXPECT_FALSE(turn_unknown_address_);
442 }
443
388 void TestTurnSendData() { 444 void TestTurnSendData() {
389 turn_port_->PrepareAddress(); 445 turn_port_->PrepareAddress();
390 EXPECT_TRUE_WAIT(turn_ready_, kTimeout); 446 EXPECT_TRUE_WAIT(turn_ready_, kTimeout);
391 CreateUdpPort(); 447 CreateUdpPort();
392 udp_port_->PrepareAddress(); 448 udp_port_->PrepareAddress();
393 EXPECT_TRUE_WAIT(udp_ready_, kTimeout); 449 EXPECT_TRUE_WAIT(udp_ready_, kTimeout);
394 // Create connections and send pings. 450 // Create connections and send pings.
395 Connection* conn1 = turn_port_->CreateConnection( 451 Connection* conn1 = turn_port_->CreateConnection(
396 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE); 452 udp_port_->Candidates()[0], Port::ORIGIN_MESSAGE);
397 Connection* conn2 = udp_port_->CreateConnection( 453 Connection* conn2 = udp_port_->CreateConnection(
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 TestTurnConnection(); 743 TestTurnConnection();
688 } 744 }
689 745
690 // Test that we can establish a TCP connection with TURN server. 746 // Test that we can establish a TCP connection with TURN server.
691 TEST_F(TurnPortTest, TestTurnTcpConnection) { 747 TEST_F(TurnPortTest, TestTurnTcpConnection) {
692 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 748 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
693 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr); 749 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnTcpProtoAddr);
694 TestTurnConnection(); 750 TestTurnConnection();
695 } 751 }
696 752
753 // Test that if a connection on a TURN port is destroyed, the TURN port can
754 // still receive ping on that connection as if it is from an unknown address.
755 // If the connection is created again, it will be used to receive ping.
756 TEST_F(TurnPortTest, TestDestoryTurnConnection) {
757 CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
758 TestDestroyTurnConnection();
759 }
760
761 // Similar to above, except that this test will use the shared socket.
762 TEST_F(TurnPortTest, TestDestoryTurnConnectionUsingSharedSocket) {
763 CreateSharedTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
764 TestDestroyTurnConnection();
765 }
766
697 // Test that we fail to create a connection when we want to use TLS over TCP. 767 // 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. 768 // This test should be removed once we have TLS support.
699 TEST_F(TurnPortTest, TestTurnTlsTcpConnectionFails) { 769 TEST_F(TurnPortTest, TestTurnTlsTcpConnectionFails) {
700 cricket::ProtocolAddress secure_addr(kTurnTcpProtoAddr.address, 770 cricket::ProtocolAddress secure_addr(kTurnTcpProtoAddr.address,
701 kTurnTcpProtoAddr.proto, 771 kTurnTcpProtoAddr.proto,
702 true); 772 true);
703 CreateTurnPort(kTurnUsername, kTurnPassword, secure_addr); 773 CreateTurnPort(kTurnUsername, kTurnPassword, secure_addr);
704 turn_port_->PrepareAddress(); 774 turn_port_->PrepareAddress();
705 EXPECT_TRUE_WAIT(turn_error_, kTimeout); 775 EXPECT_TRUE_WAIT(turn_error_, kTimeout);
706 ASSERT_EQ(0U, turn_port_->Candidates().size()); 776 ASSERT_EQ(0U, turn_port_->Candidates().size());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 turn_port_->PrepareAddress(); 877 turn_port_->PrepareAddress();
808 ASSERT_TRUE_WAIT(turn_error_, kTimeout); 878 ASSERT_TRUE_WAIT(turn_error_, kTimeout);
809 EXPECT_TRUE(turn_port_->Candidates().empty()); 879 EXPECT_TRUE(turn_port_->Candidates().empty());
810 turn_port_.reset(); 880 turn_port_.reset();
811 rtc::Thread::Current()->Post(this, MSG_TESTFINISH); 881 rtc::Thread::Current()->Post(this, MSG_TESTFINISH);
812 // Waiting for above message to be processed. 882 // Waiting for above message to be processed.
813 ASSERT_TRUE_WAIT(test_finish_, kTimeout); 883 ASSERT_TRUE_WAIT(test_finish_, kTimeout);
814 EXPECT_EQ(last_fd_count, GetFDCount()); 884 EXPECT_EQ(last_fd_count, GetFDCount());
815 } 885 }
816 #endif 886 #endif
OLDNEW
« webrtc/p2p/base/turnport.cc ('K') | « webrtc/p2p/base/turnport.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698