Chromium Code Reviews

Side by Side Diff: webrtc/p2p/quic/quictransportchannel_unittest.cc

Issue 1888903002: Fix QuicSession to unbuffer data when the QuicTransportChannel reconnects (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Respond to pthatcher comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « webrtc/p2p/quic/quictransportchannel.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 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 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 77 matching lines...)
88 88
89 // Peer who establishes a handshake using a QuicTransportChannel, which wraps 89 // Peer who establishes a handshake using a QuicTransportChannel, which wraps
90 // a FailableTransportChannel to simulate network connectivity and ICE 90 // a FailableTransportChannel to simulate network connectivity and ICE
91 // negotiation. 91 // negotiation.
92 class QuicTestPeer : public sigslot::has_slots<> { 92 class QuicTestPeer : public sigslot::has_slots<> {
93 public: 93 public:
94 explicit QuicTestPeer(const std::string& name) 94 explicit QuicTestPeer(const std::string& name)
95 : name_(name), 95 : name_(name),
96 bytes_sent_(0), 96 bytes_sent_(0),
97 ice_channel_(name_, 0), 97 ice_channel_(name_, 0),
98 quic_channel_(&ice_channel_) { 98 quic_channel_(&ice_channel_),
99 incoming_stream_count_(0) {
99 quic_channel_.SignalReadPacket.connect( 100 quic_channel_.SignalReadPacket.connect(
100 this, &QuicTestPeer::OnTransportChannelReadPacket); 101 this, &QuicTestPeer::OnTransportChannelReadPacket);
101 quic_channel_.SignalIncomingStream.connect(this, 102 quic_channel_.SignalIncomingStream.connect(this,
102 &QuicTestPeer::OnIncomingStream); 103 &QuicTestPeer::OnIncomingStream);
103 quic_channel_.SignalClosed.connect(this, &QuicTestPeer::OnClosed); 104 quic_channel_.SignalClosed.connect(this, &QuicTestPeer::OnClosed);
104 ice_channel_.SetAsync(true); 105 ice_channel_.SetAsync(true);
105 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = 106 rtc::scoped_refptr<rtc::RTCCertificate> local_cert =
106 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( 107 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
107 rtc::SSLIdentity::Generate(name_, rtc::KT_DEFAULT))); 108 rtc::SSLIdentity::Generate(name_, rtc::KT_DEFAULT)));
108 quic_channel_.SetLocalCertificate(local_cert); 109 quic_channel_.SetLocalCertificate(local_cert);
(...skipping 88 matching lines...)
197 FailableTransportChannel* ice_channel() { return &ice_channel_; } 198 FailableTransportChannel* ice_channel() { return &ice_channel_; }
198 199
199 QuicTransportChannel* quic_channel() { return &quic_channel_; } 200 QuicTransportChannel* quic_channel() { return &quic_channel_; }
200 201
201 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() { 202 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() {
202 return local_fingerprint_; 203 return local_fingerprint_;
203 } 204 }
204 205
205 ReliableQuicStream* incoming_quic_stream() { return incoming_quic_stream_; } 206 ReliableQuicStream* incoming_quic_stream() { return incoming_quic_stream_; }
206 207
208 size_t incoming_stream_count() const { return incoming_stream_count_; }
209
207 bool signal_closed_emitted() const { return signal_closed_emitted_; } 210 bool signal_closed_emitted() const { return signal_closed_emitted_; }
208 211
209 private: 212 private:
210 // QuicTransportChannel callbacks. 213 // QuicTransportChannel callbacks.
211 void OnTransportChannelReadPacket(TransportChannel* channel, 214 void OnTransportChannelReadPacket(TransportChannel* channel,
212 const char* data, 215 const char* data,
213 size_t size, 216 size_t size,
214 const rtc::PacketTime& packet_time, 217 const rtc::PacketTime& packet_time,
215 int flags) { 218 int flags) {
216 bytes_received_ += size; 219 bytes_received_ += size;
217 // Only SRTP packets should have the bypass flag set. 220 // Only SRTP packets should have the bypass flag set.
218 int expected_flags = IsRtpLeadByte(data[0]) ? cricket::PF_SRTP_BYPASS : 0; 221 int expected_flags = IsRtpLeadByte(data[0]) ? cricket::PF_SRTP_BYPASS : 0;
219 ASSERT_EQ(expected_flags, flags); 222 ASSERT_EQ(expected_flags, flags);
220 } 223 }
221 void OnIncomingStream(ReliableQuicStream* stream) { 224 void OnIncomingStream(ReliableQuicStream* stream) {
222 incoming_quic_stream_ = stream; 225 incoming_quic_stream_ = stream;
226 ++incoming_stream_count_;
223 } 227 }
224 void OnClosed() { signal_closed_emitted_ = true; } 228 void OnClosed() { signal_closed_emitted_ = true; }
225 229
226 std::string name_; // Channel name. 230 std::string name_; // Channel name.
227 size_t bytes_sent_; // Bytes sent by QUIC channel. 231 size_t bytes_sent_; // Bytes sent by QUIC channel.
228 size_t bytes_received_; // Bytes received by QUIC channel. 232 size_t bytes_received_; // Bytes received by QUIC channel.
229 FailableTransportChannel ice_channel_; // Simulates an ICE channel. 233 FailableTransportChannel ice_channel_; // Simulates an ICE channel.
230 QuicTransportChannel quic_channel_; // QUIC channel to test. 234 QuicTransportChannel quic_channel_; // QUIC channel to test.
231 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_; 235 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_;
232 ReliableQuicStream* incoming_quic_stream_ = nullptr; 236 ReliableQuicStream* incoming_quic_stream_ = nullptr;
237 size_t incoming_stream_count_;
233 bool signal_closed_emitted_ = false; 238 bool signal_closed_emitted_ = false;
234 }; 239 };
235 240
236 class QuicTransportChannelTest : public testing::Test { 241 class QuicTransportChannelTest : public testing::Test {
237 public: 242 public:
238 QuicTransportChannelTest() : peer1_("P1"), peer2_("P2") {} 243 QuicTransportChannelTest() : peer1_("P1"), peer2_("P2") {}
239 244
240 // Performs negotiation before QUIC handshake, then connects the fake 245 // Performs negotiation before QUIC handshake, then connects the fake
241 // transport channels of each peer. As a side effect, the QUIC channels 246 // transport channels of each peer. As a side effect, the QUIC channels
242 // start sending handshake messages. |peer1_| has a client role and |peer2_| 247 // start sending handshake messages. |peer1_| has a client role and |peer2_|
(...skipping 264 matching lines...)
507 Connect(); 512 Connect();
508 EXPECT_EQ(nullptr, peer1_.quic_channel()->CreateQuicStream()); 513 EXPECT_EQ(nullptr, peer1_.quic_channel()->CreateQuicStream());
509 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); 514 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs);
510 ReliableQuicStream* stream = peer1_.quic_channel()->CreateQuicStream(); 515 ReliableQuicStream* stream = peer1_.quic_channel()->CreateQuicStream();
511 ASSERT_NE(nullptr, stream); 516 ASSERT_NE(nullptr, stream);
512 stream->Write("Hi", 2); 517 stream->Write("Hi", 2);
513 EXPECT_TRUE_WAIT(peer2_.incoming_quic_stream() != nullptr, kTimeoutMs); 518 EXPECT_TRUE_WAIT(peer2_.incoming_quic_stream() != nullptr, kTimeoutMs);
514 EXPECT_EQ(stream->id(), peer2_.incoming_quic_stream()->id()); 519 EXPECT_EQ(stream->id(), peer2_.incoming_quic_stream()->id());
515 } 520 }
516 521
522 // Test that if the QuicTransportChannel is unwritable, then all outgoing QUIC
523 // streams can send data once the QuicTransprotChannel becomes writable again.
524 TEST_F(QuicTransportChannelTest, OutgoingQuicStreamSendsDataAfterReconnect) {
525 Connect();
526 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs);
527 ReliableQuicStream* stream1 = peer1_.quic_channel()->CreateQuicStream();
528 ASSERT_NE(nullptr, stream1);
529 ReliableQuicStream* stream2 = peer1_.quic_channel()->CreateQuicStream();
530 ASSERT_NE(nullptr, stream2);
531
532 peer1_.ice_channel()->SetWritable(false);
533 stream1->Write("First", 5);
534 EXPECT_EQ(5u, stream1->queued_data_bytes());
535 stream2->Write("Second", 6);
536 EXPECT_EQ(6u, stream2->queued_data_bytes());
537 EXPECT_EQ(0u, peer2_.incoming_stream_count());
538
539 peer1_.ice_channel()->SetWritable(true);
540 EXPECT_EQ_WAIT(0u, stream1->queued_data_bytes(), kTimeoutMs);
541 EXPECT_EQ_WAIT(0u, stream2->queued_data_bytes(), kTimeoutMs);
542 EXPECT_EQ_WAIT(2u, peer2_.incoming_stream_count(), kTimeoutMs);
543 }
544
517 // Test that SignalClosed is emitted when the QuicConnection closes. 545 // Test that SignalClosed is emitted when the QuicConnection closes.
518 TEST_F(QuicTransportChannelTest, SignalClosedEmitted) { 546 TEST_F(QuicTransportChannelTest, SignalClosedEmitted) {
519 Connect(); 547 Connect();
520 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); 548 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs);
521 ASSERT_FALSE(peer1_.signal_closed_emitted()); 549 ASSERT_FALSE(peer1_.signal_closed_emitted());
522 ReliableQuicStream* stream = peer1_.quic_channel()->CreateQuicStream(); 550 ReliableQuicStream* stream = peer1_.quic_channel()->CreateQuicStream();
523 ASSERT_NE(nullptr, stream); 551 ASSERT_NE(nullptr, stream);
524 stream->CloseConnectionWithDetails(net::QuicErrorCode::QUIC_NO_ERROR, 552 stream->CloseConnectionWithDetails(net::QuicErrorCode::QUIC_NO_ERROR,
525 "Closing QUIC for testing"); 553 "Closing QUIC for testing");
526 EXPECT_TRUE(peer1_.signal_closed_emitted()); 554 EXPECT_TRUE(peer1_.signal_closed_emitted());
527 EXPECT_TRUE_WAIT(peer2_.signal_closed_emitted(), kTimeoutMs); 555 EXPECT_TRUE_WAIT(peer2_.signal_closed_emitted(), kTimeoutMs);
528 } 556 }
OLDNEW
« no previous file with comments | « webrtc/p2p/quic/quictransportchannel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine