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

Side by Side Diff: net/tools/quic/quic_server_session_test.cc

Issue 786123002: Update from https://crrev.com/307330 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 | « net/tools/quic/quic_server_session.cc ('k') | net/tools/quic/quic_socket_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/tools/quic/quic_server_session.h" 5 #include "net/tools/quic/quic_server_session.h"
6 6
7 #include "net/quic/crypto/cached_network_parameters.h" 7 #include "net/quic/crypto/cached_network_parameters.h"
8 #include "net/quic/crypto/quic_crypto_server_config.h" 8 #include "net/quic/crypto/quic_crypto_server_config.h"
9 #include "net/quic/crypto/quic_random.h" 9 #include "net/quic/crypto/quic_random.h"
10 #include "net/quic/quic_connection.h" 10 #include "net/quic/quic_connection.h"
(...skipping 19 matching lines...) Expand all
30 using net::test::QuicDataStreamPeer; 30 using net::test::QuicDataStreamPeer;
31 using net::test::QuicSentPacketManagerPeer; 31 using net::test::QuicSentPacketManagerPeer;
32 using net::test::QuicSessionPeer; 32 using net::test::QuicSessionPeer;
33 using net::test::QuicSustainedBandwidthRecorderPeer; 33 using net::test::QuicSustainedBandwidthRecorderPeer;
34 using net::test::SupportedVersions; 34 using net::test::SupportedVersions;
35 using net::test::ValueRestore; 35 using net::test::ValueRestore;
36 using net::test::kClientDataStreamId1; 36 using net::test::kClientDataStreamId1;
37 using net::test::kClientDataStreamId2; 37 using net::test::kClientDataStreamId2;
38 using net::test::kClientDataStreamId3; 38 using net::test::kClientDataStreamId3;
39 using net::test::kClientDataStreamId4; 39 using net::test::kClientDataStreamId4;
40 using std::string;
40 using testing::StrictMock; 41 using testing::StrictMock;
41 using testing::_; 42 using testing::_;
42 43
43 namespace net { 44 namespace net {
44 namespace tools { 45 namespace tools {
45 namespace test { 46 namespace test {
46 47
47 class QuicServerSessionPeer { 48 class QuicServerSessionPeer {
48 public: 49 public:
49 static QuicDataStream* GetIncomingDataStream( 50 static QuicDataStream* GetIncomingDataStream(
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 private: 299 private:
299 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); 300 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream);
300 }; 301 };
301 302
302 TEST_P(QuicServerSessionTest, BandwidthEstimates) { 303 TEST_P(QuicServerSessionTest, BandwidthEstimates) {
303 if (version() <= QUIC_VERSION_21) { 304 if (version() <= QUIC_VERSION_21) {
304 return; 305 return;
305 } 306 }
306 307
307 // Test that bandwidth estimate updates are sent to the client, only after the 308 // Test that bandwidth estimate updates are sent to the client, only after the
308 // bandwidth estimate has changes sufficiently, and enough time has passed. 309 // bandwidth estimate has changes sufficiently, and enough time has passed,
310 // and we don't have any other data to write.
309 311
310 int32 bandwidth_estimate_kbytes_per_second = 123; 312 int32 bandwidth_estimate_kbytes_per_second = 123;
311 int32 max_bandwidth_estimate_kbytes_per_second = 134; 313 int32 max_bandwidth_estimate_kbytes_per_second = 134;
312 int32 max_bandwidth_estimate_timestamp = 1122334455; 314 int32 max_bandwidth_estimate_timestamp = 1122334455;
313 const string serving_region = "not a real region"; 315 const string serving_region = "not a real region";
314 session_->set_serving_region(serving_region); 316 session_->set_serving_region(serving_region);
315 317
316 MockQuicCryptoServerStream* crypto_stream = 318 MockQuicCryptoServerStream* crypto_stream =
317 new MockQuicCryptoServerStream(crypto_config_, session_.get()); 319 new MockQuicCryptoServerStream(crypto_config_, session_.get());
318 QuicServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); 320 QuicServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream);
319 321
320 // Set some initial bandwidth values. 322 // Set some initial bandwidth values.
321 QuicSentPacketManager* sent_packet_manager = 323 QuicSentPacketManager* sent_packet_manager =
322 QuicConnectionPeer::GetSentPacketManager(session_->connection()); 324 QuicConnectionPeer::GetSentPacketManager(session_->connection());
323 QuicSustainedBandwidthRecorder& bandwidth_recorder = 325 QuicSustainedBandwidthRecorder& bandwidth_recorder =
324 QuicSentPacketManagerPeer::GetBandwidthRecorder(sent_packet_manager); 326 QuicSentPacketManagerPeer::GetBandwidthRecorder(sent_packet_manager);
325 // Seed an rtt measurement equal to the initial default rtt. 327 // Seed an rtt measurement equal to the initial default rtt.
326 RttStats* rtt_stats = 328 RttStats* rtt_stats =
327 QuicSentPacketManagerPeer::GetRttStats(sent_packet_manager); 329 QuicSentPacketManagerPeer::GetRttStats(sent_packet_manager);
328 rtt_stats->UpdateRtt(QuicTime::Delta::FromMicroseconds( 330 rtt_stats->UpdateRtt(QuicTime::Delta::FromMicroseconds(
329 rtt_stats->initial_rtt_us()), QuicTime::Delta::Zero(), QuicTime::Zero()); 331 rtt_stats->initial_rtt_us()), QuicTime::Delta::Zero(), QuicTime::Zero());
330 QuicSustainedBandwidthRecorderPeer::SetBandwidthEstimate( 332 QuicSustainedBandwidthRecorderPeer::SetBandwidthEstimate(
331 &bandwidth_recorder, bandwidth_estimate_kbytes_per_second); 333 &bandwidth_recorder, bandwidth_estimate_kbytes_per_second);
332 QuicSustainedBandwidthRecorderPeer::SetMaxBandwidthEstimate( 334 QuicSustainedBandwidthRecorderPeer::SetMaxBandwidthEstimate(
333 &bandwidth_recorder, max_bandwidth_estimate_kbytes_per_second, 335 &bandwidth_recorder, max_bandwidth_estimate_kbytes_per_second,
334 max_bandwidth_estimate_timestamp); 336 max_bandwidth_estimate_timestamp);
337 // Queue up some pending data.
338 session_->MarkWriteBlocked(kCryptoStreamId,
339 QuicWriteBlockedList::kHighestPriority);
340 EXPECT_TRUE(session_->HasDataToWrite());
335 341
336 // There will be no update sent yet - not enough time has passed. 342 // There will be no update sent yet - not enough time has passed.
337 QuicTime now = QuicTime::Zero(); 343 QuicTime now = QuicTime::Zero();
338 session_->OnCongestionWindowChange(now); 344 session_->OnCongestionWindowChange(now);
339 345
340 // Bandwidth estimate has now changed sufficiently but not enough time has 346 // Bandwidth estimate has now changed sufficiently but not enough time has
341 // passed to send a Server Config Update. 347 // passed to send a Server Config Update.
342 bandwidth_estimate_kbytes_per_second = 348 bandwidth_estimate_kbytes_per_second =
343 bandwidth_estimate_kbytes_per_second * 1.6; 349 bandwidth_estimate_kbytes_per_second * 1.6;
344 session_->OnCongestionWindowChange(now); 350 session_->OnCongestionWindowChange(now);
345 351
346 // Bandwidth estimate has now changed sufficiently and enough time has passed, 352 // Bandwidth estimate has now changed sufficiently and enough time has passed,
347 // but not enough packets have been sent. 353 // but not enough packets have been sent.
348 int64 srtt_ms = 354 int64 srtt_ms =
349 sent_packet_manager->GetRttStats()->smoothed_rtt().ToMilliseconds(); 355 sent_packet_manager->GetRttStats()->smoothed_rtt().ToMilliseconds();
350 now = now.Add(QuicTime::Delta::FromMilliseconds( 356 now = now.Add(QuicTime::Delta::FromMilliseconds(
351 kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms)); 357 kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms));
352 session_->OnCongestionWindowChange(now); 358 session_->OnCongestionWindowChange(now);
353 359
360 // The connection no longer has pending data to be written.
361 session_->OnCanWrite();
362 EXPECT_FALSE(session_->HasDataToWrite());
363 session_->OnCongestionWindowChange(now);
364
354 // Bandwidth estimate has now changed sufficiently, enough time has passed, 365 // Bandwidth estimate has now changed sufficiently, enough time has passed,
355 // and enough packets have been sent. 366 // and enough packets have been sent.
356 QuicConnectionPeer::SetSequenceNumberOfLastSentPacket( 367 QuicConnectionPeer::SetSequenceNumberOfLastSentPacket(
357 session_->connection(), kMinPacketsBetweenServerConfigUpdates); 368 session_->connection(), kMinPacketsBetweenServerConfigUpdates);
358 369
359 // Verify that the proto has exactly the values we expect. 370 // Verify that the proto has exactly the values we expect.
360 CachedNetworkParameters expected_network_params; 371 CachedNetworkParameters expected_network_params;
361 expected_network_params.set_bandwidth_estimate_bytes_per_second( 372 expected_network_params.set_bandwidth_estimate_bytes_per_second(
362 bandwidth_recorder.BandwidthEstimate().ToBytesPerSecond()); 373 bandwidth_recorder.BandwidthEstimate().ToBytesPerSecond());
363 expected_network_params.set_max_bandwidth_estimate_bytes_per_second( 374 expected_network_params.set_max_bandwidth_estimate_bytes_per_second(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 cached_network_params.set_serving_region(kTestServingRegion); 429 cached_network_params.set_serving_region(kTestServingRegion);
419 crypto_stream->set_previous_cached_network_params(cached_network_params); 430 crypto_stream->set_previous_cached_network_params(cached_network_params);
420 EXPECT_CALL(*connection_, ResumeConnectionState(_)).Times(1); 431 EXPECT_CALL(*connection_, ResumeConnectionState(_)).Times(1);
421 session_->OnConfigNegotiated(); 432 session_->OnConfigNegotiated();
422 } 433 }
423 434
424 } // namespace 435 } // namespace
425 } // namespace test 436 } // namespace test
426 } // namespace tools 437 } // namespace tools
427 } // namespace net 438 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_server_session.cc ('k') | net/tools/quic/quic_socket_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698