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

Side by Side Diff: net/quic/chromium/quic_chromium_client_session_test.cc

Issue 2319343004: Makes migration on write error asynchronous to avoid reentrancy issues (Closed)
Patch Set: responses to comments Created 4 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 // 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/quic/chromium/quic_chromium_client_session.h" 5 #include "net/quic/chromium/quic_chromium_client_session.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
11 #include "base/run_loop.h"
11 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
12 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
13 #include "net/cert/cert_verify_result.h" 14 #include "net/cert/cert_verify_result.h"
14 #include "net/http/transport_security_state.h" 15 #include "net/http/transport_security_state.h"
15 #include "net/log/test_net_log.h" 16 #include "net/log/test_net_log.h"
16 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" 17 #include "net/quic/chromium/crypto/proof_verifier_chromium.h"
17 #include "net/quic/chromium/quic_chromium_alarm_factory.h" 18 #include "net/quic/chromium/quic_chromium_alarm_factory.h"
18 #include "net/quic/chromium/quic_chromium_client_session_peer.h" 19 #include "net/quic/chromium/quic_chromium_client_session_peer.h"
19 #include "net/quic/chromium/quic_chromium_connection_helper.h" 20 #include "net/quic/chromium/quic_chromium_connection_helper.h"
20 #include "net/quic/chromium/quic_chromium_packet_reader.h" 21 #include "net/quic/chromium/quic_chromium_packet_reader.h"
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 std::unique_ptr<QuicChromiumPacketReader> new_reader( 420 std::unique_ptr<QuicChromiumPacketReader> new_reader(
420 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(), 421 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(),
421 kQuicYieldAfterPacketsRead, 422 kQuicYieldAfterPacketsRead,
422 QuicTime::Delta::FromMilliseconds( 423 QuicTime::Delta::FromMilliseconds(
423 kQuicYieldAfterDurationMilliseconds), 424 kQuicYieldAfterDurationMilliseconds),
424 bound_net_log_.bound())); 425 bound_net_log_.bound()));
425 std::unique_ptr<QuicChromiumPacketWriter> new_writer( 426 std::unique_ptr<QuicChromiumPacketWriter> new_writer(
426 CreateQuicChromiumPacketWriter(new_socket.get(), session_.get())); 427 CreateQuicChromiumPacketWriter(new_socket.get(), session_.get()));
427 428
428 // Migrate session. 429 // Migrate session.
429 EXPECT_TRUE(session_->MigrateToSocket(std::move(new_socket), 430 EXPECT_TRUE(session_->MigrateToSocket(
430 std::move(new_reader), 431 std::move(new_socket), std::move(new_reader), std::move(new_writer)));
431 std::move(new_writer), nullptr)); 432 // Spin message loop to complete migration.
433 base::RunLoop().RunUntilIdle();
432 434
433 // Write data to session. 435 // Write data to session.
434 QuicChromiumClientStream* stream = 436 QuicChromiumClientStream* stream =
435 session_->CreateOutgoingDynamicStream(kDefaultPriority); 437 session_->CreateOutgoingDynamicStream(kDefaultPriority);
436 struct iovec iov[1]; 438 struct iovec iov[1];
437 iov[0].iov_base = data; 439 iov[0].iov_base = data;
438 iov[0].iov_len = 4; 440 iov[0].iov_len = 4;
439 session_->WritevData(stream, stream->id(), 441 session_->WritevData(stream, stream->id(),
440 QuicIOVector(iov, arraysize(iov), 4), 0, false, nullptr); 442 QuicIOVector(iov, arraysize(iov), 4), 0, false, nullptr);
441 443
(...skipping 27 matching lines...) Expand all
469 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(), 471 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(),
470 kQuicYieldAfterPacketsRead, 472 kQuicYieldAfterPacketsRead,
471 QuicTime::Delta::FromMilliseconds( 473 QuicTime::Delta::FromMilliseconds(
472 kQuicYieldAfterDurationMilliseconds), 474 kQuicYieldAfterDurationMilliseconds),
473 bound_net_log_.bound())); 475 bound_net_log_.bound()));
474 std::unique_ptr<QuicChromiumPacketWriter> new_writer( 476 std::unique_ptr<QuicChromiumPacketWriter> new_writer(
475 CreateQuicChromiumPacketWriter(new_socket.get(), session_.get())); 477 CreateQuicChromiumPacketWriter(new_socket.get(), session_.get()));
476 478
477 // Migrate session. 479 // Migrate session.
478 if (i < kMaxReadersPerQuicSession - 1) { 480 if (i < kMaxReadersPerQuicSession - 1) {
479 EXPECT_TRUE(session_->MigrateToSocket(std::move(new_socket), 481 EXPECT_TRUE(session_->MigrateToSocket(
480 std::move(new_reader), 482 std::move(new_socket), std::move(new_reader), std::move(new_writer)));
481 std::move(new_writer), nullptr)); 483 // Spin message loop to complete migration.
484 base::RunLoop().RunUntilIdle();
482 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 485 EXPECT_TRUE(socket_data.AllReadDataConsumed());
483 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 486 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
484 } else { 487 } else {
485 // Max readers exceeded. 488 // Max readers exceeded.
486 EXPECT_FALSE(session_->MigrateToSocket(std::move(new_socket), 489 EXPECT_FALSE(session_->MigrateToSocket(
487 std::move(new_reader), 490 std::move(new_socket), std::move(new_reader), std::move(new_writer)));
488 std::move(new_writer), nullptr));
489
490 EXPECT_FALSE(socket_data.AllReadDataConsumed()); 491 EXPECT_FALSE(socket_data.AllReadDataConsumed());
491 EXPECT_FALSE(socket_data.AllWriteDataConsumed()); 492 EXPECT_FALSE(socket_data.AllWriteDataConsumed());
492 } 493 }
493 } 494 }
494 } 495 }
495 496
496 TEST_P(QuicChromiumClientSessionTest, MigrateToSocketReadError) { 497 TEST_P(QuicChromiumClientSessionTest, MigrateToSocketReadError) {
497 std::unique_ptr<QuicEncryptedPacket> client_ping( 498 std::unique_ptr<QuicEncryptedPacket> client_ping(
498 client_maker_.MakePingPacket(1, /*include_version=*/false)); 499 client_maker_.MakePingPacket(1, /*include_version=*/false));
499 std::unique_ptr<QuicEncryptedPacket> server_ping( 500 std::unique_ptr<QuicEncryptedPacket> server_ping(
(...skipping 30 matching lines...) Expand all
530 std::unique_ptr<QuicChromiumPacketReader> new_reader( 531 std::unique_ptr<QuicChromiumPacketReader> new_reader(
531 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(), 532 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(),
532 kQuicYieldAfterPacketsRead, 533 kQuicYieldAfterPacketsRead,
533 QuicTime::Delta::FromMilliseconds( 534 QuicTime::Delta::FromMilliseconds(
534 kQuicYieldAfterDurationMilliseconds), 535 kQuicYieldAfterDurationMilliseconds),
535 bound_net_log_.bound())); 536 bound_net_log_.bound()));
536 std::unique_ptr<QuicChromiumPacketWriter> new_writer( 537 std::unique_ptr<QuicChromiumPacketWriter> new_writer(
537 CreateQuicChromiumPacketWriter(new_socket.get(), session_.get())); 538 CreateQuicChromiumPacketWriter(new_socket.get(), session_.get()));
538 539
539 // Store old socket and migrate session. 540 // Store old socket and migrate session.
540 EXPECT_TRUE(session_->MigrateToSocket(std::move(new_socket), 541 EXPECT_TRUE(session_->MigrateToSocket(
541 std::move(new_reader), 542 std::move(new_socket), std::move(new_reader), std::move(new_writer)));
542 std::move(new_writer), nullptr)); 543 // Spin message loop to complete migration.
544 base::RunLoop().RunUntilIdle();
543 545
544 // Read error on old socket does not impact session. 546 // Read error on old socket does not impact session.
545 EXPECT_TRUE(socket_data_->IsPaused()); 547 EXPECT_TRUE(socket_data_->IsPaused());
546 socket_data_->Resume(); 548 socket_data_->Resume();
547 EXPECT_TRUE(session_->connection()->connected()); 549 EXPECT_TRUE(session_->connection()->connected());
548 EXPECT_TRUE(new_socket_data.IsPaused()); 550 EXPECT_TRUE(new_socket_data.IsPaused());
549 new_socket_data.Resume(); 551 new_socket_data.Resume();
550 552
551 // Read error on new socket causes session close. 553 // Read error on new socket causes session close.
552 EXPECT_TRUE(new_socket_data.IsPaused()); 554 EXPECT_TRUE(new_socket_data.IsPaused());
553 EXPECT_TRUE(session_->connection()->connected()); 555 EXPECT_TRUE(session_->connection()->connected());
554 new_socket_data.Resume(); 556 new_socket_data.Resume();
555 EXPECT_FALSE(session_->connection()->connected()); 557 EXPECT_FALSE(session_->connection()->connected());
556 558
557 EXPECT_TRUE(socket_data_->AllReadDataConsumed()); 559 EXPECT_TRUE(socket_data_->AllReadDataConsumed());
558 EXPECT_TRUE(socket_data_->AllWriteDataConsumed()); 560 EXPECT_TRUE(socket_data_->AllWriteDataConsumed());
559 EXPECT_TRUE(new_socket_data.AllReadDataConsumed()); 561 EXPECT_TRUE(new_socket_data.AllReadDataConsumed());
560 EXPECT_TRUE(new_socket_data.AllWriteDataConsumed()); 562 EXPECT_TRUE(new_socket_data.AllWriteDataConsumed());
561 } 563 }
562 564
563 TEST_P(QuicChromiumClientSessionTest, MigrateToSocketWriteError) {
564 Initialize();
565 CompleteCryptoHandshake();
566
567 std::unique_ptr<QuicEncryptedPacket> ping(
568 client_maker_.MakePingPacket(1, /*include_version=*/true));
569 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
570 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 1),
571 MockWrite(SYNCHRONOUS, ERR_FAILED, 2)};
572 SequencedSocketData socket_data(reads, arraysize(reads), writes,
573 arraysize(writes));
574 socket_factory_.AddSocketDataProvider(&socket_data);
575
576 // Create connected socket.
577 std::unique_ptr<DatagramClientSocket> new_socket =
578 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND,
579 base::Bind(&base::RandInt),
580 &net_log_, NetLog::Source());
581 EXPECT_THAT(new_socket->Connect(kIpEndPoint), IsOk());
582
583 // Create reader and writer.
584 std::unique_ptr<QuicChromiumPacketReader> new_reader(
585 new QuicChromiumPacketReader(new_socket.get(), &clock_, session_.get(),
586 kQuicYieldAfterPacketsRead,
587 QuicTime::Delta::FromMilliseconds(
588 kQuicYieldAfterDurationMilliseconds),
589 bound_net_log_.bound()));
590 std::unique_ptr<QuicChromiumPacketWriter> new_writer(
591 CreateQuicChromiumPacketWriter(new_socket.get(), session_.get()));
592
593 // Migrate session.
594 EXPECT_TRUE(session_->MigrateToSocket(std::move(new_socket),
595 std::move(new_reader),
596 std::move(new_writer), nullptr));
597
598 // Write error on new socket causes session close.
599 EXPECT_TRUE(session_->connection()->connected());
600 session_->connection()->SendPing();
601 EXPECT_FALSE(session_->connection()->connected());
602
603 EXPECT_TRUE(socket_data.AllReadDataConsumed());
604 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
605 }
606
607 } // namespace 565 } // namespace
608 } // namespace test 566 } // namespace test
609 } // namespace net 567 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698