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

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

Issue 137893008: WriteBlockedList for QUIC that prioritizes Crypto and Headers streams (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/test_tools/quic_session_peer.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_dispatcher.h" 5 #include "net/tools/quic/quic_dispatcher.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "net/quic/crypto/crypto_handshake.h" 10 #include "net/quic/crypto/crypto_handshake.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN); 290 return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN);
291 } else { 291 } else {
292 return QuicPacketWriterWrapper::WritePacket( 292 return QuicPacketWriterWrapper::WritePacket(
293 buffer, buf_len, self_address, peer_address, blocked_writer); 293 buffer, buf_len, self_address, peer_address, blocked_writer);
294 } 294 }
295 } 295 }
296 296
297 bool write_blocked_; 297 bool write_blocked_;
298 }; 298 };
299 299
300 class QuicWriteBlockedListTest : public QuicDispatcherTest { 300 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
301 public: 301 public:
302 virtual void SetUp() { 302 virtual void SetUp() {
303 writer_ = new BlockingWriter; 303 writer_ = new BlockingWriter;
304 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); 304 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_);
305 305
306 IPEndPoint addr(net::test::Loopback4(), 1); 306 IPEndPoint addr(net::test::Loopback4(), 1);
307 307
308 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr)) 308 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr))
309 .WillOnce(testing::Return(CreateSession( 309 .WillOnce(testing::Return(CreateSession(
310 &dispatcher_, 1, addr, &session1_))); 310 &dispatcher_, 1, addr, &session1_)));
(...skipping 16 matching lines...) Expand all
327 bool SetBlocked() { 327 bool SetBlocked() {
328 writer_->write_blocked_ = true; 328 writer_->write_blocked_ = true;
329 return true; 329 return true;
330 } 330 }
331 331
332 protected: 332 protected:
333 BlockingWriter* writer_; 333 BlockingWriter* writer_;
334 QuicDispatcher::WriteBlockedList* blocked_list_; 334 QuicDispatcher::WriteBlockedList* blocked_list_;
335 }; 335 };
336 336
337 TEST_F(QuicWriteBlockedListTest, BasicOnCanWrite) { 337 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) {
338 // No OnCanWrite calls because no connections are blocked. 338 // No OnCanWrite calls because no connections are blocked.
339 dispatcher_.OnCanWrite(); 339 dispatcher_.OnCanWrite();
340 340
341 // Register connection 1 for events, and make sure it's notified. 341 // Register connection 1 for events, and make sure it's notified.
342 SetBlocked(); 342 SetBlocked();
343 dispatcher_.OnWriteBlocked(connection1()); 343 dispatcher_.OnWriteBlocked(connection1());
344 EXPECT_CALL(*connection1(), OnCanWrite()); 344 EXPECT_CALL(*connection1(), OnCanWrite());
345 dispatcher_.OnCanWrite(); 345 dispatcher_.OnCanWrite();
346 346
347 // It should get only one notification. 347 // It should get only one notification.
348 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 348 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
349 EXPECT_FALSE(dispatcher_.OnCanWrite()); 349 EXPECT_FALSE(dispatcher_.OnCanWrite());
350 } 350 }
351 351
352 TEST_F(QuicWriteBlockedListTest, OnCanWriteOrder) { 352 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteOrder) {
353 // Make sure we handle events in order. 353 // Make sure we handle events in order.
354 InSequence s; 354 InSequence s;
355 SetBlocked(); 355 SetBlocked();
356 dispatcher_.OnWriteBlocked(connection1()); 356 dispatcher_.OnWriteBlocked(connection1());
357 dispatcher_.OnWriteBlocked(connection2()); 357 dispatcher_.OnWriteBlocked(connection2());
358 EXPECT_CALL(*connection1(), OnCanWrite()); 358 EXPECT_CALL(*connection1(), OnCanWrite());
359 EXPECT_CALL(*connection2(), OnCanWrite()); 359 EXPECT_CALL(*connection2(), OnCanWrite());
360 dispatcher_.OnCanWrite(); 360 dispatcher_.OnCanWrite();
361 361
362 // Check the other ordering. 362 // Check the other ordering.
363 SetBlocked(); 363 SetBlocked();
364 dispatcher_.OnWriteBlocked(connection2()); 364 dispatcher_.OnWriteBlocked(connection2());
365 dispatcher_.OnWriteBlocked(connection1()); 365 dispatcher_.OnWriteBlocked(connection1());
366 EXPECT_CALL(*connection2(), OnCanWrite()); 366 EXPECT_CALL(*connection2(), OnCanWrite());
367 EXPECT_CALL(*connection1(), OnCanWrite()); 367 EXPECT_CALL(*connection1(), OnCanWrite());
368 dispatcher_.OnCanWrite(); 368 dispatcher_.OnCanWrite();
369 } 369 }
370 370
371 TEST_F(QuicWriteBlockedListTest, OnCanWriteRemove) { 371 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteRemove) {
372 // Add and remove one connction. 372 // Add and remove one connction.
373 SetBlocked(); 373 SetBlocked();
374 dispatcher_.OnWriteBlocked(connection1()); 374 dispatcher_.OnWriteBlocked(connection1());
375 blocked_list_->erase(connection1()); 375 blocked_list_->erase(connection1());
376 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 376 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
377 dispatcher_.OnCanWrite(); 377 dispatcher_.OnCanWrite();
378 378
379 // Add and remove one connction and make sure it doesn't affect others. 379 // Add and remove one connction and make sure it doesn't affect others.
380 SetBlocked(); 380 SetBlocked();
381 dispatcher_.OnWriteBlocked(connection1()); 381 dispatcher_.OnWriteBlocked(connection1());
382 dispatcher_.OnWriteBlocked(connection2()); 382 dispatcher_.OnWriteBlocked(connection2());
383 blocked_list_->erase(connection1()); 383 blocked_list_->erase(connection1());
384 EXPECT_CALL(*connection2(), OnCanWrite()); 384 EXPECT_CALL(*connection2(), OnCanWrite());
385 dispatcher_.OnCanWrite(); 385 dispatcher_.OnCanWrite();
386 386
387 // Add it, remove it, and add it back and make sure things are OK. 387 // Add it, remove it, and add it back and make sure things are OK.
388 SetBlocked(); 388 SetBlocked();
389 dispatcher_.OnWriteBlocked(connection1()); 389 dispatcher_.OnWriteBlocked(connection1());
390 blocked_list_->erase(connection1()); 390 blocked_list_->erase(connection1());
391 dispatcher_.OnWriteBlocked(connection1()); 391 dispatcher_.OnWriteBlocked(connection1());
392 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); 392 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1);
393 dispatcher_.OnCanWrite(); 393 dispatcher_.OnCanWrite();
394 } 394 }
395 395
396 TEST_F(QuicWriteBlockedListTest, DoubleAdd) { 396 TEST_F(QuicDispatcherWriteBlockedListTest, DoubleAdd) {
397 // Make sure a double add does not necessitate a double remove. 397 // Make sure a double add does not necessitate a double remove.
398 SetBlocked(); 398 SetBlocked();
399 dispatcher_.OnWriteBlocked(connection1()); 399 dispatcher_.OnWriteBlocked(connection1());
400 dispatcher_.OnWriteBlocked(connection1()); 400 dispatcher_.OnWriteBlocked(connection1());
401 blocked_list_->erase(connection1()); 401 blocked_list_->erase(connection1());
402 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 402 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
403 dispatcher_.OnCanWrite(); 403 dispatcher_.OnCanWrite();
404 404
405 // Make sure a double add does not result in two OnCanWrite calls. 405 // Make sure a double add does not result in two OnCanWrite calls.
406 SetBlocked(); 406 SetBlocked();
407 dispatcher_.OnWriteBlocked(connection1()); 407 dispatcher_.OnWriteBlocked(connection1());
408 dispatcher_.OnWriteBlocked(connection1()); 408 dispatcher_.OnWriteBlocked(connection1());
409 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); 409 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1);
410 dispatcher_.OnCanWrite(); 410 dispatcher_.OnCanWrite();
411 } 411 }
412 412
413 TEST_F(QuicWriteBlockedListTest, OnCanWriteHandleBlock) { 413 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteHandleBlock) {
414 // Finally make sure if we write block on a write call, we stop calling. 414 // Finally make sure if we write block on a write call, we stop calling.
415 InSequence s; 415 InSequence s;
416 SetBlocked(); 416 SetBlocked();
417 dispatcher_.OnWriteBlocked(connection1()); 417 dispatcher_.OnWriteBlocked(connection1());
418 dispatcher_.OnWriteBlocked(connection2()); 418 dispatcher_.OnWriteBlocked(connection2());
419 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce( 419 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce(
420 Invoke(this, &QuicWriteBlockedListTest::SetBlocked)); 420 Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked));
421 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); 421 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0);
422 dispatcher_.OnCanWrite(); 422 dispatcher_.OnCanWrite();
423 423
424 // And we'll resume where we left off when we get another call. 424 // And we'll resume where we left off when we get another call.
425 EXPECT_CALL(*connection2(), OnCanWrite()); 425 EXPECT_CALL(*connection2(), OnCanWrite());
426 dispatcher_.OnCanWrite(); 426 dispatcher_.OnCanWrite();
427 } 427 }
428 428
429 TEST_F(QuicWriteBlockedListTest, LimitedWrites) { 429 TEST_F(QuicDispatcherWriteBlockedListTest, LimitedWrites) {
430 // Make sure we call both writers. The first will register for more writing 430 // Make sure we call both writers. The first will register for more writing
431 // but should not be immediately called due to limits. 431 // but should not be immediately called due to limits.
432 InSequence s; 432 InSequence s;
433 SetBlocked(); 433 SetBlocked();
434 dispatcher_.OnWriteBlocked(connection1()); 434 dispatcher_.OnWriteBlocked(connection1());
435 dispatcher_.OnWriteBlocked(connection2()); 435 dispatcher_.OnWriteBlocked(connection2());
436 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce(Return(true)); 436 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce(Return(true));
437 EXPECT_CALL(*connection2(), OnCanWrite()).WillOnce(Return(false)); 437 EXPECT_CALL(*connection2(), OnCanWrite()).WillOnce(Return(false));
438 dispatcher_.OnCanWrite(); 438 dispatcher_.OnCanWrite();
439 439
440 // Now call OnCanWrite again, and connection1 should get its second chance 440 // Now call OnCanWrite again, and connection1 should get its second chance
441 EXPECT_CALL(*connection1(), OnCanWrite()); 441 EXPECT_CALL(*connection1(), OnCanWrite());
442 dispatcher_.OnCanWrite(); 442 dispatcher_.OnCanWrite();
443 } 443 }
444 444
445 TEST_F(QuicWriteBlockedListTest, TestWriteLimits) { 445 TEST_F(QuicDispatcherWriteBlockedListTest, TestWriteLimits) {
446 // Finally make sure if we write block on a write call, we stop calling. 446 // Finally make sure if we write block on a write call, we stop calling.
447 InSequence s; 447 InSequence s;
448 SetBlocked(); 448 SetBlocked();
449 dispatcher_.OnWriteBlocked(connection1()); 449 dispatcher_.OnWriteBlocked(connection1());
450 dispatcher_.OnWriteBlocked(connection2()); 450 dispatcher_.OnWriteBlocked(connection2());
451 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce( 451 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce(
452 Invoke(this, &QuicWriteBlockedListTest::SetBlocked)); 452 Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked));
453 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); 453 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0);
454 dispatcher_.OnCanWrite(); 454 dispatcher_.OnCanWrite();
455 455
456 // And we'll resume where we left off when we get another call. 456 // And we'll resume where we left off when we get another call.
457 EXPECT_CALL(*connection2(), OnCanWrite()); 457 EXPECT_CALL(*connection2(), OnCanWrite());
458 dispatcher_.OnCanWrite(); 458 dispatcher_.OnCanWrite();
459 } 459 }
460 460
461 } // namespace 461 } // namespace
462 } // namespace test 462 } // namespace test
463 } // namespace tools 463 } // namespace tools
464 } // namespace net 464 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_session_peer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698