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

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

Issue 2184013003: Delay destroying a port if new connections are created and destroyed. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 4 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/port.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 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 10
(...skipping 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 2585
2586 // Simulate a connection that succeeds, and then is destroyed. 2586 // Simulate a connection that succeeds, and then is destroyed.
2587 StartConnectAndStopChannels(&ch1, &ch2); 2587 StartConnectAndStopChannels(&ch1, &ch2);
2588 2588
2589 // After the connection is destroyed, the port should not be destroyed. 2589 // After the connection is destroyed, the port should not be destroyed.
2590 rtc::Thread::Current()->ProcessMessages(kTimeout); 2590 rtc::Thread::Current()->ProcessMessages(kTimeout);
2591 EXPECT_FALSE(destroyed()); 2591 EXPECT_FALSE(destroyed());
2592 } 2592 }
2593 2593
2594 // This test case verifies that the CONTROLLED port does time out, but only 2594 // This test case verifies that the CONTROLLED port does time out, but only
2595 // after connectivity is lost. 2595 // after connectivity is lost and no connection was created during the timeout
2596 // period.
2596 TEST_F(PortTest, TestControlledTimeout) { 2597 TEST_F(PortTest, TestControlledTimeout) {
2598 rtc::ScopedFakeClock clock;
2597 UDPPort* port1 = CreateUdpPort(kLocalAddr1); 2599 UDPPort* port1 = CreateUdpPort(kLocalAddr1);
2598 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); 2600 port1->SetIceRole(cricket::ICEROLE_CONTROLLING);
2599 port1->SetIceTiebreaker(kTiebreaker1); 2601 port1->SetIceTiebreaker(kTiebreaker1);
2600 2602
2601 UDPPort* port2 = CreateUdpPort(kLocalAddr2); 2603 UDPPort* port2 = CreateUdpPort(kLocalAddr2);
2602 ConnectToSignalDestroyed(port2); 2604 ConnectToSignalDestroyed(port2);
2603 port2->set_timeout_delay(10); // milliseconds 2605 port2->set_timeout_delay(100); // milliseconds
2604 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); 2606 port2->SetIceRole(cricket::ICEROLE_CONTROLLED);
2605 port2->SetIceTiebreaker(kTiebreaker2); 2607 port2->SetIceTiebreaker(kTiebreaker2);
2606 2608
2607 // The connection must not be destroyed before a connection is attempted. 2609 // The connection must not be destroyed before a connection is attempted.
2608 EXPECT_FALSE(destroyed()); 2610 EXPECT_FALSE(destroyed());
2609 2611
2610 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); 2612 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
2611 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); 2613 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
2612 2614
2613 // Set up channels and ensure both ports will be deleted. 2615 // Set up channels and ensure both ports will be deleted.
2614 TestChannel ch1(port1); 2616 TestChannel ch1(port1);
2615 TestChannel ch2(port2); 2617 TestChannel ch2(port2);
2616 2618
2617 // Simulate a connection that succeeds, and then is destroyed. 2619 // Simulate a connection that succeeds, and then is destroyed.
2618 StartConnectAndStopChannels(&ch1, &ch2); 2620 StartConnectAndStopChannels(&ch1, &ch2);
2619 2621
2620 // The controlled port should be destroyed after 10 milliseconds. 2622 SIMULATED_WAIT(false, 80, clock);
2621 EXPECT_TRUE_WAIT(destroyed(), kTimeout); 2623 ch2.CreateConnection(GetCandidate(ch1.port()));
2624
2625 // ch2 creates a connection so it will not be destroyed.
2626 SIMULATED_WAIT(destroyed(), 80, clock);
2627 EXPECT_FALSE(destroyed());
2628
2629 // Even if ch2 stops now, it won't be destroyed until 100ms after the
2630 // connection is destroyed.
2631 ch2.Stop();
2632 SIMULATED_WAIT(destroyed(), 80, clock);
2633 EXPECT_FALSE(destroyed());
2634
2635 // The controlled port should be destroyed after timeout.
2636 EXPECT_TRUE_SIMULATED_WAIT(destroyed(), 30, clock);
2622 } 2637 }
2623 2638
2624 // This test case verifies that if the role of a port changes from controlled 2639 // This test case verifies that if the role of a port changes from controlled
2625 // to controlling after all connections fail, the port will not be destroyed. 2640 // to controlling after all connections fail, the port will not be destroyed.
2626 TEST_F(PortTest, TestControlledToControllingNotDestroyed) { 2641 TEST_F(PortTest, TestControlledToControllingNotDestroyed) {
2627 UDPPort* port1 = CreateUdpPort(kLocalAddr1); 2642 UDPPort* port1 = CreateUdpPort(kLocalAddr1);
2628 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); 2643 port1->SetIceRole(cricket::ICEROLE_CONTROLLING);
2629 port1->SetIceTiebreaker(kTiebreaker1); 2644 port1->SetIceTiebreaker(kTiebreaker1);
2630 2645
2631 UDPPort* port2 = CreateUdpPort(kLocalAddr2); 2646 UDPPort* port2 = CreateUdpPort(kLocalAddr2);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2714 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); 2729 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE);
2715 EXPECT_NE(conn1, conn2); 2730 EXPECT_NE(conn1, conn2);
2716 conn_in_use = port->GetConnection(address); 2731 conn_in_use = port->GetConnection(address);
2717 EXPECT_EQ(conn2, conn_in_use); 2732 EXPECT_EQ(conn2, conn_in_use);
2718 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation()); 2733 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation());
2719 2734
2720 // Make sure the new connection was not deleted. 2735 // Make sure the new connection was not deleted.
2721 rtc::Thread::Current()->ProcessMessages(300); 2736 rtc::Thread::Current()->ProcessMessages(300);
2722 EXPECT_TRUE(port->GetConnection(address) != nullptr); 2737 EXPECT_TRUE(port->GetConnection(address) != nullptr);
2723 } 2738 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698