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

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

Issue 1288553010: TcpPort Reconnect should inform upper layer to start sending again (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 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 | « no previous file | webrtc/p2p/base/tcpport.cc » ('j') | 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 225 }
226 void CreateConnection() { 226 void CreateConnection() {
227 conn_ = src_->CreateConnection(GetCandidate(dst_), Port::ORIGIN_MESSAGE); 227 conn_ = src_->CreateConnection(GetCandidate(dst_), Port::ORIGIN_MESSAGE);
228 IceMode remote_ice_mode = 228 IceMode remote_ice_mode =
229 (ice_mode_ == ICEMODE_FULL) ? ICEMODE_LITE : ICEMODE_FULL; 229 (ice_mode_ == ICEMODE_FULL) ? ICEMODE_LITE : ICEMODE_FULL;
230 conn_->set_remote_ice_mode(remote_ice_mode); 230 conn_->set_remote_ice_mode(remote_ice_mode);
231 conn_->set_use_candidate_attr(remote_ice_mode == ICEMODE_FULL); 231 conn_->set_use_candidate_attr(remote_ice_mode == ICEMODE_FULL);
232 conn_->SignalStateChange.connect( 232 conn_->SignalStateChange.connect(
233 this, &TestChannel::OnConnectionStateChange); 233 this, &TestChannel::OnConnectionStateChange);
234 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed); 234 conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed);
235 conn_->SignalReadyToSend.connect(this,
236 &TestChannel::OnConnectionReadyToSend);
237 connection_ready_to_send_ = false;
235 } 238 }
236 void OnConnectionStateChange(Connection* conn) { 239 void OnConnectionStateChange(Connection* conn) {
237 if (conn->write_state() == Connection::STATE_WRITABLE) { 240 if (conn->write_state() == Connection::STATE_WRITABLE) {
238 conn->set_use_candidate_attr(true); 241 conn->set_use_candidate_attr(true);
239 nominated_ = true; 242 nominated_ = true;
240 } 243 }
241 } 244 }
242 void AcceptConnection() { 245 void AcceptConnection() {
243 ASSERT_TRUE(remote_request_.get() != NULL); 246 ASSERT_TRUE(remote_request_.get() != NULL);
244 Candidate c = GetCandidate(dst_); 247 Candidate c = GetCandidate(dst_);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 317
315 void OnSrcPortDestroyed(PortInterface* port) { 318 void OnSrcPortDestroyed(PortInterface* port) {
316 Port* destroyed_src = src_.release(); 319 Port* destroyed_src = src_.release();
317 ASSERT_EQ(destroyed_src, port); 320 ASSERT_EQ(destroyed_src, port);
318 } 321 }
319 322
320 Port* src_port() { return src_.get(); } 323 Port* src_port() { return src_.get(); }
321 324
322 bool nominated() const { return nominated_; } 325 bool nominated() const { return nominated_; }
323 326
327 void set_connection_ready_to_send(bool ready) {
328 connection_ready_to_send_ = ready;
329 }
330 bool connection_ready_to_send() const {
331 return connection_ready_to_send_;
332 }
333
324 private: 334 private:
335 // ReadyToSend will only issue after a Connection recovers from EWOULDBLOCK.
336 void OnConnectionReadyToSend(Connection* conn) {
337 ASSERT_EQ(conn, conn_);
338 connection_ready_to_send_ = true;
339 }
340
325 IceMode ice_mode_; 341 IceMode ice_mode_;
326 rtc::scoped_ptr<Port> src_; 342 rtc::scoped_ptr<Port> src_;
327 Port* dst_; 343 Port* dst_;
328 344
329 int complete_count_; 345 int complete_count_;
330 Connection* conn_; 346 Connection* conn_;
331 SocketAddress remote_address_; 347 SocketAddress remote_address_;
332 rtc::scoped_ptr<StunMessage> remote_request_; 348 rtc::scoped_ptr<StunMessage> remote_request_;
333 std::string remote_frag_; 349 std::string remote_frag_;
334 bool nominated_; 350 bool nominated_;
351 bool connection_ready_to_send_ = false;
335 }; 352 };
336 353
337 class PortTest : public testing::Test, public sigslot::has_slots<> { 354 class PortTest : public testing::Test, public sigslot::has_slots<> {
338 public: 355 public:
339 PortTest() 356 PortTest()
340 : main_(rtc::Thread::Current()), 357 : main_(rtc::Thread::Current()),
341 pss_(new rtc::PhysicalSocketServer), 358 pss_(new rtc::PhysicalSocketServer),
342 ss_(new rtc::VirtualSocketServer(pss_.get())), 359 ss_(new rtc::VirtualSocketServer(pss_.get())),
343 ss_scope_(ss_.get()), 360 ss_scope_(ss_.get()),
344 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), 361 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32),
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 ch1.CreateConnection(); 634 ch1.CreateConnection();
618 ConnectStartedChannels(&ch1, &ch2); 635 ConnectStartedChannels(&ch1, &ch2);
619 636
620 // Shorten the timeout period. 637 // Shorten the timeout period.
621 const int kTcpReconnectTimeout = kTimeout; 638 const int kTcpReconnectTimeout = kTimeout;
622 static_cast<TCPConnection*>(ch1.conn()) 639 static_cast<TCPConnection*>(ch1.conn())
623 ->set_reconnection_timeout(kTcpReconnectTimeout); 640 ->set_reconnection_timeout(kTcpReconnectTimeout);
624 static_cast<TCPConnection*>(ch2.conn()) 641 static_cast<TCPConnection*>(ch2.conn())
625 ->set_reconnection_timeout(kTcpReconnectTimeout); 642 ->set_reconnection_timeout(kTcpReconnectTimeout);
626 643
644 EXPECT_FALSE(ch1.connection_ready_to_send());
645 EXPECT_FALSE(ch2.connection_ready_to_send());
646
627 // Once connected, disconnect them. 647 // Once connected, disconnect them.
628 DisconnectTcpTestChannels(&ch1, &ch2); 648 DisconnectTcpTestChannels(&ch1, &ch2);
629 649
630 if (send_after_disconnected || ping_after_disconnected) { 650 if (send_after_disconnected || ping_after_disconnected) {
631 if (send_after_disconnected) { 651 if (send_after_disconnected) {
632 // First SendData after disconnect should fail but will trigger 652 // First SendData after disconnect should fail but will trigger
633 // reconnect. 653 // reconnect.
634 EXPECT_EQ(-1, ch1.SendData(data, static_cast<int>(strlen(data)))); 654 EXPECT_EQ(-1, ch1.SendData(data, static_cast<int>(strlen(data))));
635 } 655 }
636 656
637 if (ping_after_disconnected) { 657 if (ping_after_disconnected) {
638 // Ping should trigger reconnect. 658 // Ping should trigger reconnect.
639 ch1.Ping(); 659 ch1.Ping();
640 } 660 }
641 661
642 // Wait for channel's outgoing TCPConnection connected. 662 // Wait for channel's outgoing TCPConnection connected.
643 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout); 663 EXPECT_TRUE_WAIT(ch1.conn()->connected(), kTimeout);
644 664
645 // Verify that we could still connect channels. 665 // Verify that we could still connect channels.
646 ConnectStartedChannels(&ch1, &ch2); 666 ConnectStartedChannels(&ch1, &ch2);
667 EXPECT_TRUE_WAIT(ch1.connection_ready_to_send(),
668 kTcpReconnectTimeout);
669 // Channel2 is the passive one so a new connection is created during
670 // reconnect. This new connection should never have issued EWOULDBLOCK
671 // hence the connection_ready_to_send() should be false.
672 EXPECT_FALSE(ch2.connection_ready_to_send());
647 } else { 673 } else {
648 EXPECT_EQ(ch1.conn()->write_state(), Connection::STATE_WRITABLE); 674 EXPECT_EQ(ch1.conn()->write_state(), Connection::STATE_WRITABLE);
649 EXPECT_TRUE_WAIT( 675 EXPECT_TRUE_WAIT(
650 ch1.conn()->write_state() == Connection::STATE_WRITE_TIMEOUT, 676 ch1.conn()->write_state() == Connection::STATE_WRITE_TIMEOUT,
651 kTcpReconnectTimeout + kTimeout); 677 kTcpReconnectTimeout + kTimeout);
678 EXPECT_FALSE(ch1.connection_ready_to_send());
679 EXPECT_FALSE(ch2.connection_ready_to_send());
652 } 680 }
653 681
654 // Tear down and ensure that goes smoothly. 682 // Tear down and ensure that goes smoothly.
655 ch1.Stop(); 683 ch1.Stop();
656 ch2.Stop(); 684 ch2.Stop();
657 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); 685 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout);
658 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); 686 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout);
659 } 687 }
660 688
661 void SetIceProtocolType(cricket::IceProtocolType protocol) { 689 void SetIceProtocolType(cricket::IceProtocolType protocol) {
(...skipping 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 // Set up channels and ensure both ports will be deleted. 2669 // Set up channels and ensure both ports will be deleted.
2642 TestChannel ch1(port1, port2); 2670 TestChannel ch1(port1, port2);
2643 TestChannel ch2(port2, port1); 2671 TestChannel ch2(port2, port1);
2644 2672
2645 // Simulate a connection that succeeds, and then is destroyed. 2673 // Simulate a connection that succeeds, and then is destroyed.
2646 StartConnectAndStopChannels(&ch1, &ch2); 2674 StartConnectAndStopChannels(&ch1, &ch2);
2647 2675
2648 // The controlled port should be destroyed after 10 milliseconds. 2676 // The controlled port should be destroyed after 10 milliseconds.
2649 EXPECT_TRUE_WAIT(destroyed(), kTimeout); 2677 EXPECT_TRUE_WAIT(destroyed(), kTimeout);
2650 } 2678 }
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/tcpport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698