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

Side by Side Diff: talk/media/sctp/sctpdataengine_unittest.cc

Issue 1266033005: Added send-thresholding and fixed text packet dumping. Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added a test and more pthatcher@ comments. Created 5 years, 3 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
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 virtual void SetUp() { 234 virtual void SetUp() {
235 engine_.reset(new cricket::SctpDataEngine()); 235 engine_.reset(new cricket::SctpDataEngine());
236 } 236 }
237 237
238 void SetupConnectedChannels() { 238 void SetupConnectedChannels() {
239 net1_.reset(new SctpFakeNetworkInterface(rtc::Thread::Current())); 239 net1_.reset(new SctpFakeNetworkInterface(rtc::Thread::Current()));
240 net2_.reset(new SctpFakeNetworkInterface(rtc::Thread::Current())); 240 net2_.reset(new SctpFakeNetworkInterface(rtc::Thread::Current()));
241 recv1_.reset(new SctpFakeDataReceiver()); 241 recv1_.reset(new SctpFakeDataReceiver());
242 recv2_.reset(new SctpFakeDataReceiver()); 242 recv2_.reset(new SctpFakeDataReceiver());
243 chan1_ready_to_send_count_ = 0;
244 chan2_ready_to_send_count_ = 0;
243 chan1_.reset(CreateChannel(net1_.get(), recv1_.get())); 245 chan1_.reset(CreateChannel(net1_.get(), recv1_.get()));
244 chan1_->set_debug_name("chan1/connector"); 246 chan1_->set_debug_name("chan1/connector");
247 chan1_->SignalReadyToSend.connect(
248 this, &SctpDataMediaChannelTest::OnChan1ReadyToSend);
245 chan2_.reset(CreateChannel(net2_.get(), recv2_.get())); 249 chan2_.reset(CreateChannel(net2_.get(), recv2_.get()));
246 chan2_->set_debug_name("chan2/listener"); 250 chan2_->set_debug_name("chan2/listener");
251 chan2_->SignalReadyToSend.connect(
252 this, &SctpDataMediaChannelTest::OnChan2ReadyToSend);
247 // Setup two connected channels ready to send and receive. 253 // Setup two connected channels ready to send and receive.
248 net1_->SetDestination(chan2_.get()); 254 net1_->SetDestination(chan2_.get());
249 net2_->SetDestination(chan1_.get()); 255 net2_->SetDestination(chan1_.get());
250 256
251 LOG(LS_VERBOSE) << "Channel setup ----------------------------- "; 257 LOG(LS_VERBOSE) << "Channel setup ----------------------------- ";
252 AddStream(1); 258 AddStream(1);
253 AddStream(2); 259 AddStream(2);
254 260
255 LOG(LS_VERBOSE) << "Connect the channels -----------------------------"; 261 LOG(LS_VERBOSE) << "Connect the channels -----------------------------";
256 // chan1 wants to setup a data connection. 262 // chan1 wants to setup a data connection.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 329 }
324 } 330 }
325 return !thread->IsQuitting(); 331 return !thread->IsQuitting();
326 } 332 }
327 333
328 cricket::SctpDataMediaChannel* channel1() { return chan1_.get(); } 334 cricket::SctpDataMediaChannel* channel1() { return chan1_.get(); }
329 cricket::SctpDataMediaChannel* channel2() { return chan2_.get(); } 335 cricket::SctpDataMediaChannel* channel2() { return chan2_.get(); }
330 SctpFakeDataReceiver* receiver1() { return recv1_.get(); } 336 SctpFakeDataReceiver* receiver1() { return recv1_.get(); }
331 SctpFakeDataReceiver* receiver2() { return recv2_.get(); } 337 SctpFakeDataReceiver* receiver2() { return recv2_.get(); }
332 338
339 int channel1_ready_to_send_count() { return chan1_ready_to_send_count_; }
340 int channel2_ready_to_send_count() { return chan2_ready_to_send_count_; }
333 private: 341 private:
334 rtc::scoped_ptr<cricket::SctpDataEngine> engine_; 342 rtc::scoped_ptr<cricket::SctpDataEngine> engine_;
335 rtc::scoped_ptr<SctpFakeNetworkInterface> net1_; 343 rtc::scoped_ptr<SctpFakeNetworkInterface> net1_;
336 rtc::scoped_ptr<SctpFakeNetworkInterface> net2_; 344 rtc::scoped_ptr<SctpFakeNetworkInterface> net2_;
337 rtc::scoped_ptr<SctpFakeDataReceiver> recv1_; 345 rtc::scoped_ptr<SctpFakeDataReceiver> recv1_;
338 rtc::scoped_ptr<SctpFakeDataReceiver> recv2_; 346 rtc::scoped_ptr<SctpFakeDataReceiver> recv2_;
339 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan1_; 347 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan1_;
340 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan2_; 348 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan2_;
349
350 int chan1_ready_to_send_count_;
351 int chan2_ready_to_send_count_;
352
353 void OnChan1ReadyToSend(bool send) { if (send) chan1_ready_to_send_count_++; }
tommi 2015/08/27 11:38:02 nit: use postfix ++ (style guide thing) it's also
lally1 2015/08/27 17:56:09 Done.
354 void OnChan2ReadyToSend(bool send) { if (send) chan2_ready_to_send_count_++; }
341 }; 355 };
342 356
343 // Verifies that SignalReadyToSend is fired. 357 // Verifies that SignalReadyToSend is fired.
344 TEST_F(SctpDataMediaChannelTest, SignalReadyToSend) { 358 TEST_F(SctpDataMediaChannelTest, SignalReadyToSend) {
345 SetupConnectedChannels(); 359 SetupConnectedChannels();
346 360
347 SignalReadyToSendObserver signal_observer_1; 361 SignalReadyToSendObserver signal_observer_1;
348 SignalReadyToSendObserver signal_observer_2; 362 SignalReadyToSendObserver signal_observer_2;
349 363
350 channel1()->SignalReadyToSend.connect(&signal_observer_1, 364 channel1()->SignalReadyToSend.connect(&signal_observer_1,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 493
480 channel2()->RemoveSendStream(2); 494 channel2()->RemoveSendStream(2);
481 channel2()->RemoveSendStream(3); 495 channel2()->RemoveSendStream(3);
482 channel2()->RemoveSendStream(4); 496 channel2()->RemoveSendStream(4);
483 EXPECT_TRUE_WAIT(chan_2_sig_receiver.WasStreamClosed(1), 1000); 497 EXPECT_TRUE_WAIT(chan_2_sig_receiver.WasStreamClosed(1), 1000);
484 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(2), 1000); 498 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(2), 1000);
485 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(3), 1000); 499 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(3), 1000);
486 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(4), 1000); 500 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(4), 1000);
487 } 501 }
488 502
503 TEST_F(SctpDataMediaChannelTest, EngineSignalsRightChannel) {
504 SetupConnectedChannels();
505 EXPECT_TRUE_WAIT(channel1()->socket() != NULL, 1000);
506 struct socket *sock = const_cast<struct socket*>(channel1()->socket());
507 int prior_count = channel1_ready_to_send_count();
508 cricket::SctpDataEngine::SendThresholdCallback(sock, 0);
509 EXPECT_GT(channel1_ready_to_send_count(), prior_count);
510 }
511
489 // Flaky on Linux and Windows. See webrtc:4453. 512 // Flaky on Linux and Windows. See webrtc:4453.
490 #if defined(WEBRTC_WIN) || defined(WEBRTC_LINUX) 513 #if defined(WEBRTC_WIN) || defined(WEBRTC_LINUX)
491 #define MAYBE_ReusesAStream DISABLED_ReusesAStream 514 #define MAYBE_ReusesAStream DISABLED_ReusesAStream
492 #else 515 #else
493 #define MAYBE_ReusesAStream ReusesAStream 516 #define MAYBE_ReusesAStream ReusesAStream
494 #endif 517 #endif
495 TEST_F(SctpDataMediaChannelTest, MAYBE_ReusesAStream) { 518 TEST_F(SctpDataMediaChannelTest, MAYBE_ReusesAStream) {
496 // Shut down channel 1, then open it up again for reuse. 519 // Shut down channel 1, then open it up again for reuse.
497 SetupConnectedChannels(); 520 SetupConnectedChannels();
498 cricket::SendDataResult result; 521 cricket::SendDataResult result;
499 SignalChannelClosedObserver chan_2_sig_receiver; 522 SignalChannelClosedObserver chan_2_sig_receiver;
500 chan_2_sig_receiver.BindSelf(channel2()); 523 chan_2_sig_receiver.BindSelf(channel2());
501 524
502 ASSERT_TRUE(SendData(channel1(), 1, "hello?", &result)); 525 ASSERT_TRUE(SendData(channel1(), 1, "hello?", &result));
503 EXPECT_EQ(cricket::SDR_SUCCESS, result); 526 EXPECT_EQ(cricket::SDR_SUCCESS, result);
504 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hello?"), 1000); 527 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hello?"), 1000);
505 528
506 channel1()->RemoveSendStream(1); 529 channel1()->RemoveSendStream(1);
507 EXPECT_TRUE_WAIT(chan_2_sig_receiver.WasStreamClosed(1), 1000); 530 EXPECT_TRUE_WAIT(chan_2_sig_receiver.WasStreamClosed(1), 1000);
508 // Channel 1 is gone now. 531 // Channel 1 is gone now.
509 532
510 // Create a new channel 1. 533 // Create a new channel 1.
511 AddStream(1); 534 AddStream(1);
512 ASSERT_TRUE(SendData(channel1(), 1, "hi?", &result)); 535 ASSERT_TRUE(SendData(channel1(), 1, "hi?", &result));
513 EXPECT_EQ(cricket::SDR_SUCCESS, result); 536 EXPECT_EQ(cricket::SDR_SUCCESS, result);
514 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), 1000); 537 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), 1000);
515 channel1()->RemoveSendStream(1); 538 channel1()->RemoveSendStream(1);
516 EXPECT_TRUE_WAIT(chan_2_sig_receiver.StreamCloseCount(1) == 2, 1000); 539 EXPECT_TRUE_WAIT(chan_2_sig_receiver.StreamCloseCount(1) == 2, 1000);
517 } 540 }
OLDNEW
« talk/media/sctp/sctpdataengine.cc ('K') | « talk/media/sctp/sctpdataengine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698