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

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

Issue 2319343004: Makes migration on write error asynchronous to avoid reentrancy issues (Closed)
Patch Set: Avoids multiple tasks from repeating packet write. 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_stream_factory.h" 5 #include "net/quic/chromium/quic_stream_factory.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 << " " << actual_address.port(); 500 << " " << actual_address.port();
501 DVLOG(1) << "Expected address: " << expected_address.address().ToString() 501 DVLOG(1) << "Expected address: " << expected_address.address().ToString()
502 << " " << expected_address.port(); 502 << " " << expected_address.port();
503 503
504 stream.reset(); 504 stream.reset();
505 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); 505 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
506 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); 506 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
507 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); 507 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
508 } 508 }
509 509
510 // Helper methods for tests of connection migration on write error.
511 void MigrateSessionOnWriteErrorNonMigratableStream(IoMode mode);
512 void MigrateSessionOnWriteErrorMigrationDisabled(IoMode mode);
513 void MigrateSessionOnWriteError(IoMode mode);
514 void MigrateSessionOnWriteErrorNoNewNetwork(IoMode mode);
515 void MigrateSessionOnMultipleWriteErrors(IoMode mode1, IoMode mode2);
516 void MigrateSessionOnWriteErrorWithNotificationQueued(bool disconnected);
517 void MigrateSessionOnNotificationWithWriteErrorQueued(bool disconnected);
518
510 MockHostResolver host_resolver_; 519 MockHostResolver host_resolver_;
511 scoped_refptr<SSLConfigService> ssl_config_service_; 520 scoped_refptr<SSLConfigService> ssl_config_service_;
512 MockClientSocketFactory socket_factory_; 521 MockClientSocketFactory socket_factory_;
513 MockCryptoClientStreamFactory crypto_client_stream_factory_; 522 MockCryptoClientStreamFactory crypto_client_stream_factory_;
514 MockRandom random_generator_; 523 MockRandom random_generator_;
515 MockClock* clock_; // Owned by |factory_| once created. 524 MockClock* clock_; // Owned by |factory_| once created.
516 scoped_refptr<TestTaskRunner> runner_; 525 scoped_refptr<TestTaskRunner> runner_;
517 QuicVersion version_; 526 QuicVersion version_;
518 QuicTestPacketMaker client_maker_; 527 QuicTestPacketMaker client_maker_;
519 QuicTestPacketMaker server_maker_; 528 QuicTestPacketMaker server_maker_;
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); 2414 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2406 EXPECT_TRUE(HasActiveSession(host_port_pair_)); 2415 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2407 EXPECT_EQ(1u, session->GetNumActiveStreams()); 2416 EXPECT_EQ(1u, session->GetNumActiveStreams());
2408 2417
2409 stream.reset(); 2418 stream.reset();
2410 2419
2411 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 2420 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2412 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 2421 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2413 } 2422 }
2414 2423
2415 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteError) { 2424 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) {
2425 MigrateSessionOnWriteError(SYNCHRONOUS);
2426 }
2427
2428 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) {
2429 MigrateSessionOnWriteError(ASYNC);
2430 }
2431
2432 void QuicStreamFactoryTestBase::MigrateSessionOnWriteError(IoMode mode) {
2416 InitializeConnectionMigrationTest( 2433 InitializeConnectionMigrationTest(
2417 {kDefaultNetworkForTests, kNewNetworkForTests}); 2434 {kDefaultNetworkForTests, kNewNetworkForTests});
2418 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 2435 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2419 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2436 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2420 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2437 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2421 2438
2422 MockQuicData socket_data; 2439 MockQuicData socket_data;
2423 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); 2440 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2424 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); 2441 socket_data.AddWrite(mode, ERR_ADDRESS_UNREACHABLE);
2425 socket_data.AddSocketDataToFactory(&socket_factory_); 2442 socket_data.AddSocketDataToFactory(&socket_factory_);
2426 2443
2427 // Create request and QuicHttpStream. 2444 // Create request and QuicHttpStream.
2428 QuicStreamRequest request(factory_.get()); 2445 QuicStreamRequest request(factory_.get());
2429 EXPECT_EQ(ERR_IO_PENDING, 2446 EXPECT_EQ(ERR_IO_PENDING,
2430 request.Request(host_port_pair_, privacy_mode_, 2447 request.Request(host_port_pair_, privacy_mode_,
2431 /*cert_verify_flags=*/0, url_, "GET", net_log_, 2448 /*cert_verify_flags=*/0, url_, "GET", net_log_,
2432 callback_.callback())); 2449 callback_.callback()));
2433 EXPECT_EQ(OK, callback_.WaitForResult()); 2450 EXPECT_EQ(OK, callback_.WaitForResult());
2434 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); 2451 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
(...skipping 24 matching lines...) Expand all
2459 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1, true)); 2476 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1, true));
2460 socket_data1.AddSocketDataToFactory(&socket_factory_); 2477 socket_data1.AddSocketDataToFactory(&socket_factory_);
2461 2478
2462 // Send GET request on stream. This should cause a write error, which triggers 2479 // Send GET request on stream. This should cause a write error, which triggers
2463 // a connection migration attempt. 2480 // a connection migration attempt.
2464 HttpResponseInfo response; 2481 HttpResponseInfo response;
2465 HttpRequestHeaders request_headers; 2482 HttpRequestHeaders request_headers;
2466 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, 2483 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
2467 callback_.callback())); 2484 callback_.callback()));
2468 2485
2469 // Run the message loop so that data queued in the new socket is read by the 2486 // Run the message loop so that the migration attempt is executed and
2470 // packet reader. 2487 // data queued in the new socket is read by the packet reader.
2471 base::RunLoop().RunUntilIdle(); 2488 base::RunLoop().RunUntilIdle();
2472 2489
2473 // The session should now be marked as going away. Ensure that 2490 // The session should now be marked as going away. Ensure that
2474 // while it is still alive, it is no longer active. 2491 // while it is still alive, it is no longer active.
2475 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); 2492 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2476 EXPECT_FALSE(HasActiveSession(host_port_pair_)); 2493 EXPECT_FALSE(HasActiveSession(host_port_pair_));
2477 EXPECT_EQ(1u, session->GetNumActiveStreams()); 2494 EXPECT_EQ(1u, session->GetNumActiveStreams());
2478 2495
2479 // Verify that response headers on the migrated socket were delivered to the 2496 // Verify that response headers on the migrated socket were delivered to the
2480 // stream. 2497 // stream.
2481 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); 2498 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
2482 EXPECT_EQ(200, response.headers->response_code()); 2499 EXPECT_EQ(200, response.headers->response_code());
2483 2500
2484 stream.reset(); 2501 stream.reset();
2485 2502
2486 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 2503 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2487 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 2504 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2488 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); 2505 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
2489 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); 2506 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
2490 } 2507 }
2491 2508
2492 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetwork) { 2509 TEST_P(QuicStreamFactoryTest,
2510 MigrateSessionOnWriteErrorNoNewNetworkSynchronous) {
2511 MigrateSessionOnWriteErrorNoNewNetwork(SYNCHRONOUS);
2512 }
2513
2514 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) {
2515 MigrateSessionOnWriteErrorNoNewNetwork(ASYNC);
2516 }
2517
2518 void QuicStreamFactoryTestBase::MigrateSessionOnWriteErrorNoNewNetwork(
2519 IoMode mode) {
2493 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); 2520 InitializeConnectionMigrationTest({kDefaultNetworkForTests});
2494 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 2521 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2495 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2522 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2496 2523
2497 MockQuicData socket_data; 2524 MockQuicData socket_data;
2498 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); 2525 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2499 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); 2526 socket_data.AddWrite(mode, ERR_ADDRESS_UNREACHABLE);
2500 socket_data.AddSocketDataToFactory(&socket_factory_); 2527 socket_data.AddSocketDataToFactory(&socket_factory_);
2501 2528
2502 // Create request and QuicHttpStream. 2529 // Create request and QuicHttpStream.
2503 QuicStreamRequest request(factory_.get()); 2530 QuicStreamRequest request(factory_.get());
2504 EXPECT_EQ(ERR_IO_PENDING, 2531 EXPECT_EQ(ERR_IO_PENDING,
2505 request.Request(host_port_pair_, privacy_mode_, 2532 request.Request(host_port_pair_, privacy_mode_,
2506 /*cert_verify_flags=*/0, url_, "GET", net_log_, 2533 /*cert_verify_flags=*/0, url_, "GET", net_log_,
2507 callback_.callback())); 2534 callback_.callback()));
2508 EXPECT_EQ(OK, callback_.WaitForResult()); 2535 EXPECT_EQ(OK, callback_.WaitForResult());
2509 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); 2536 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
2510 EXPECT_TRUE(stream.get()); 2537 EXPECT_TRUE(stream.get());
2511 2538
2512 // Cause QUIC stream to be created. 2539 // Cause QUIC stream to be created.
2513 HttpRequestInfo request_info; 2540 HttpRequestInfo request_info;
2514 request_info.method = "GET"; 2541 request_info.method = "GET";
2515 request_info.url = GURL("https://www.example.org/"); 2542 request_info.url = GURL("https://www.example.org/");
2516 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, 2543 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2517 net_log_, CompletionCallback())); 2544 net_log_, CompletionCallback()));
2518 2545
2519 // Ensure that session is alive and active. 2546 // Ensure that session is alive and active.
2520 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); 2547 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_);
2521 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); 2548 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2522 EXPECT_TRUE(HasActiveSession(host_port_pair_)); 2549 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2523 2550
2524 // Send GET request on stream. This should cause a write error, which triggers 2551 // Send GET request on stream. This should cause a write error, which triggers
2525 // a connection migration attempt. 2552 // a connection migration attempt.
2526 HttpResponseInfo response; 2553 HttpResponseInfo response;
2527 HttpRequestHeaders request_headers; 2554 HttpRequestHeaders request_headers;
2528 EXPECT_EQ( 2555 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
2529 ERR_QUIC_PROTOCOL_ERROR, 2556 callback_.callback()));
2530 stream->SendRequest(request_headers, &response, callback_.callback())); 2557 // Run message loop to execute migration attempt.
2531 2558 base::RunLoop().RunUntilIdle();
2532 // Migration fails, and session is marked as going away. 2559 // Migration fails, and session is closed and deleted.
2560 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2533 EXPECT_FALSE(HasActiveSession(host_port_pair_)); 2561 EXPECT_FALSE(HasActiveSession(host_port_pair_));
2534 2562
2535 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 2563 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2536 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 2564 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2537 } 2565 }
2538 2566
2539 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNonMigratableStream) { 2567 TEST_P(QuicStreamFactoryTest,
2568 MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) {
2569 MigrateSessionOnWriteErrorNonMigratableStream(SYNCHRONOUS);
2570 }
2571
2572 TEST_P(QuicStreamFactoryTest,
2573 MigrateSessionOnWriteErrorNonMigratableStreamAsync) {
2574 MigrateSessionOnWriteErrorNonMigratableStream(ASYNC);
2575 }
2576
2577 void QuicStreamFactoryTestBase::MigrateSessionOnWriteErrorNonMigratableStream(
2578 IoMode mode) {
2579 DVLOG(1) << "Mode: " << ((mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC");
2540 InitializeConnectionMigrationTest( 2580 InitializeConnectionMigrationTest(
2541 {kDefaultNetworkForTests, kNewNetworkForTests}); 2581 {kDefaultNetworkForTests, kNewNetworkForTests});
2542 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 2582 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2543 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2583 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2544 2584
2545 MockQuicData socket_data; 2585 MockQuicData socket_data;
2546 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); 2586 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2547 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); 2587 socket_data.AddWrite(mode, ERR_ADDRESS_UNREACHABLE);
2548 socket_data.AddSocketDataToFactory(&socket_factory_); 2588 socket_data.AddSocketDataToFactory(&socket_factory_);
2549 2589
2550 // Create request and QuicHttpStream. 2590 // Create request and QuicHttpStream.
2551 QuicStreamRequest request(factory_.get()); 2591 QuicStreamRequest request(factory_.get());
2552 EXPECT_EQ(ERR_IO_PENDING, 2592 EXPECT_EQ(ERR_IO_PENDING,
2553 request.Request(host_port_pair_, privacy_mode_, 2593 request.Request(host_port_pair_, privacy_mode_,
2554 /*cert_verify_flags=*/0, url_, "GET", net_log_, 2594 /*cert_verify_flags=*/0, url_, "GET", net_log_,
2555 callback_.callback())); 2595 callback_.callback()));
2556 EXPECT_EQ(OK, callback_.WaitForResult()); 2596 EXPECT_EQ(OK, callback_.WaitForResult());
2557 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); 2597 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
2558 EXPECT_TRUE(stream.get()); 2598 EXPECT_TRUE(stream.get());
2559 2599
2560 // Cause QUIC stream to be created, but marked as non-migratable. 2600 // Cause QUIC stream to be created, but marked as non-migratable.
2561 HttpRequestInfo request_info; 2601 HttpRequestInfo request_info;
2562 request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION; 2602 request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION;
2563 request_info.method = "GET"; 2603 request_info.method = "GET";
2564 request_info.url = GURL("https://www.example.org/"); 2604 request_info.url = GURL("https://www.example.org/");
2565 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, 2605 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2566 net_log_, CompletionCallback())); 2606 net_log_, CompletionCallback()));
2567 2607
2568 // Ensure that session is alive and active. 2608 // Ensure that session is alive and active.
2569 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); 2609 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_);
2570 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); 2610 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2571 EXPECT_TRUE(HasActiveSession(host_port_pair_)); 2611 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2572 2612
2573 // Send GET request on stream. This should cause a write error, which triggers 2613 // Send GET request on stream. This should cause a write error, which triggers
2574 // a connection migration attempt. 2614 // a connection migration attempt.
2575 HttpResponseInfo response; 2615 HttpResponseInfo response;
2576 HttpRequestHeaders request_headers; 2616 HttpRequestHeaders request_headers;
2577 EXPECT_EQ( 2617 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
2578 ERR_QUIC_PROTOCOL_ERROR, 2618 callback_.callback()));
2579 stream->SendRequest(request_headers, &response, callback_.callback()));
2580 2619
2581 // Migration fails, and session is marked as going away. 2620 // Run message loop to execute migration attempt.
2621 base::RunLoop().RunUntilIdle();
2622
2623 // Migration fails, and session is closed and deleted.
2624 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2582 EXPECT_FALSE(HasActiveSession(host_port_pair_)); 2625 EXPECT_FALSE(HasActiveSession(host_port_pair_));
2583 2626
2584 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 2627 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2585 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 2628 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2586 } 2629 }
2587 2630
2588 TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorMigrationDisabled) { 2631 TEST_P(QuicStreamFactoryTest,
2632 MigrateSessionOnWriteErrorMigrationDisabledSynchronous) {
2633 MigrateSessionOnWriteErrorMigrationDisabled(SYNCHRONOUS);
2634 }
2635
2636 TEST_P(QuicStreamFactoryTest,
2637 MigrateSessionOnWriteErrorMigrationDisabledAsync) {
2638 MigrateSessionOnWriteErrorMigrationDisabled(ASYNC);
2639 }
2640
2641 void QuicStreamFactoryTestBase::MigrateSessionOnWriteErrorMigrationDisabled(
2642 IoMode mode) {
2589 InitializeConnectionMigrationTest( 2643 InitializeConnectionMigrationTest(
2590 {kDefaultNetworkForTests, kNewNetworkForTests}); 2644 {kDefaultNetworkForTests, kNewNetworkForTests});
2591 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 2645 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2592 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2646 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2593 2647
2594 MockQuicData socket_data; 2648 MockQuicData socket_data;
2595 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); 2649 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2596 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); 2650 socket_data.AddWrite(mode, ERR_ADDRESS_UNREACHABLE);
2597 socket_data.AddSocketDataToFactory(&socket_factory_); 2651 socket_data.AddSocketDataToFactory(&socket_factory_);
2598 2652
2599 // Create request and QuicHttpStream. 2653 // Create request and QuicHttpStream.
2600 QuicStreamRequest request(factory_.get()); 2654 QuicStreamRequest request(factory_.get());
2601 EXPECT_EQ(ERR_IO_PENDING, 2655 EXPECT_EQ(ERR_IO_PENDING,
2602 request.Request(host_port_pair_, privacy_mode_, 2656 request.Request(host_port_pair_, privacy_mode_,
2603 /*cert_verify_flags=*/0, url_, "GET", net_log_, 2657 /*cert_verify_flags=*/0, url_, "GET", net_log_,
2604 callback_.callback())); 2658 callback_.callback()));
2605 EXPECT_EQ(OK, callback_.WaitForResult()); 2659 EXPECT_EQ(OK, callback_.WaitForResult());
2606 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); 2660 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
(...skipping 12 matching lines...) Expand all
2619 EXPECT_TRUE(HasActiveSession(host_port_pair_)); 2673 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2620 2674
2621 // Set session config to have connection migration disabled. 2675 // Set session config to have connection migration disabled.
2622 QuicConfigPeer::SetReceivedDisableConnectionMigration(session->config()); 2676 QuicConfigPeer::SetReceivedDisableConnectionMigration(session->config());
2623 EXPECT_TRUE(session->config()->DisableConnectionMigration()); 2677 EXPECT_TRUE(session->config()->DisableConnectionMigration());
2624 2678
2625 // Send GET request on stream. This should cause a write error, which triggers 2679 // Send GET request on stream. This should cause a write error, which triggers
2626 // a connection migration attempt. 2680 // a connection migration attempt.
2627 HttpResponseInfo response; 2681 HttpResponseInfo response;
2628 HttpRequestHeaders request_headers; 2682 HttpRequestHeaders request_headers;
2629 EXPECT_EQ( 2683 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
2630 ERR_QUIC_PROTOCOL_ERROR, 2684 callback_.callback()));
2631 stream->SendRequest(request_headers, &response, callback_.callback())); 2685 // Run message loop to execute migration attempt.
2632 2686 base::RunLoop().RunUntilIdle();
2633 // Migration fails, and session is marked as going away. 2687 // Migration fails, and session is closed and deleted.
2634 EXPECT_FALSE(HasActiveSession(host_port_pair_)); 2688 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2635 2689 EXPECT_FALSE(HasActiveSession(host_port_pair_));
2636 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 2690 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2637 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 2691 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2638 } 2692 }
2639 2693
2694 TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) {
2695 MigrateSessionOnMultipleWriteErrors(SYNCHRONOUS, SYNCHRONOUS);
2696 }
2697
2698 TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) {
2699 MigrateSessionOnMultipleWriteErrors(SYNCHRONOUS, ASYNC);
2700 }
2701
2702 TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) {
2703 MigrateSessionOnMultipleWriteErrors(ASYNC, SYNCHRONOUS);
2704 }
2705
2706 TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) {
2707 MigrateSessionOnMultipleWriteErrors(ASYNC, ASYNC);
2708 }
2709
2710 void QuicStreamFactoryTestBase::MigrateSessionOnMultipleWriteErrors(
2711 IoMode mode1,
2712 IoMode mode2) {
2713 const int kMaxReadersPerQuicSession = 5;
2714 InitializeConnectionMigrationTest(
2715 {kDefaultNetworkForTests, kNewNetworkForTests});
2716 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2717 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2718 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2719
2720 // Set up kMaxReadersPerQuicSession socket data providers, since migration
2721 // will
2722 // cause kMaxReadersPerQuicSession write failures as the session hops
2723 // repeatedly
2724 // between the two networks.
2725 MockQuicData socket_data[kMaxReadersPerQuicSession + 1];
2726 for (int i = 0; i <= kMaxReadersPerQuicSession; ++i) {
2727 // The last socket is created but never used.
2728 if (i < kMaxReadersPerQuicSession) {
2729 socket_data[i].AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2730 socket_data[i].AddWrite((i % 2 == 0) ? mode1 : mode2, ERR_FAILED);
2731 }
2732 socket_data[i].AddSocketDataToFactory(&socket_factory_);
2733 }
2734
2735 // Create request and QuicHttpStream.
2736 QuicStreamRequest request(factory_.get());
2737 EXPECT_EQ(ERR_IO_PENDING,
2738 request.Request(host_port_pair_, privacy_mode_,
2739 /*cert_verify_flags=*/0, url_, "GET", net_log_,
2740 callback_.callback()));
2741 EXPECT_EQ(OK, callback_.WaitForResult());
2742 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
2743 EXPECT_TRUE(stream.get());
2744
2745 // Cause QUIC stream to be created.
2746 HttpRequestInfo request_info;
2747 request_info.method = "GET";
2748 request_info.url = GURL("https://www.example.org/");
2749 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2750 net_log_, CompletionCallback()));
2751
2752 // Ensure that session is alive and active.
2753 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_);
2754 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2755 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2756
2757 // Send GET request on stream. This should cause a write error, which triggers
2758 // a connection migration attempt.
2759 HttpResponseInfo response;
2760 HttpRequestHeaders request_headers;
2761 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
2762 callback_.callback()));
2763
2764 // Run the message loop so that data queued in the new socket is read by the
2765 // packet reader.
2766 base::RunLoop().RunUntilIdle();
2767
2768 // The connection should be closed because of a write error after migration.
2769 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2770 EXPECT_FALSE(HasActiveSession(host_port_pair_));
2771
2772 // EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult());
2773 // EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR,
2774 // stream->ReadResponseHeaders(callback_.callback()));
2775
2776 stream.reset();
2777 for (int i = 0; i <= kMaxReadersPerQuicSession; ++i) {
2778 DLOG(INFO) << "Socket number: " << i;
2779 EXPECT_TRUE(socket_data[i].AllReadDataConsumed());
2780 EXPECT_TRUE(socket_data[i].AllWriteDataConsumed());
2781 }
2782 }
2783
2784 TEST_P(QuicStreamFactoryTest,
2785 MigrateSessionOnWriteErrorWithNetworkDisconnectedQueued) {
2786 MigrateSessionOnWriteErrorWithNotificationQueued(/*disconnected=*/true);
2787 }
2788
2789 TEST_P(QuicStreamFactoryTest,
2790 MigrateSessionOnWriteErrorWithNetworkMadeDefaultQueued) {
2791 MigrateSessionOnWriteErrorWithNotificationQueued(/*disconnected=*/false);
2792 }
2793
2794 void QuicStreamFactoryTestBase::
2795 MigrateSessionOnWriteErrorWithNotificationQueued(bool disconnected) {
2796 InitializeConnectionMigrationTest(
2797 {kDefaultNetworkForTests, kNewNetworkForTests});
2798 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2799 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2800 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2801
2802 MockQuicData socket_data;
2803 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2804 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE);
2805 socket_data.AddSocketDataToFactory(&socket_factory_);
2806
2807 // Create request and QuicHttpStream.
2808 QuicStreamRequest request(factory_.get());
2809 EXPECT_EQ(ERR_IO_PENDING,
2810 request.Request(host_port_pair_, privacy_mode_,
2811 /*cert_verify_flags=*/0, url_, "GET", net_log_,
2812 callback_.callback()));
2813 EXPECT_EQ(OK, callback_.WaitForResult());
2814 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
2815 EXPECT_TRUE(stream.get());
2816
2817 // Cause QUIC stream to be created.
2818 HttpRequestInfo request_info;
2819 request_info.method = "GET";
2820 request_info.url = GURL("https://www.example.org/");
2821 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2822 net_log_, CompletionCallback()));
2823
2824 // Ensure that session is alive and active.
2825 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_);
2826 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2827 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2828
2829 // Set up second socket data provider that is used after
2830 // migration. The request is rewritten to this new socket, and the
2831 // response to the request is read on this new socket.
2832 MockQuicData socket_data1;
2833 socket_data1.AddWrite(
2834 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true));
2835 socket_data1.AddRead(
2836 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false));
2837 socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2838 socket_data1.AddWrite(client_maker_.MakeAckAndRstPacket(
2839 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1, true));
2840 socket_data1.AddSocketDataToFactory(&socket_factory_);
2841
2842 // First queue a network change notification in the message loop.
2843 if (disconnected) {
2844 scoped_mock_network_change_notifier_->mock_network_change_notifier()
2845 ->QueueNetworkDisconnected(kDefaultNetworkForTests);
2846 } else {
2847 scoped_mock_network_change_notifier_->mock_network_change_notifier()
2848 ->QueueNetworkMadeDefault(kNewNetworkForTests);
2849 }
2850 // Send GET request on stream. This should cause a write error,
2851 // which triggers a connection migration attempt. This will queue a
2852 // migration attempt behind the notification in the message loop.
2853 HttpResponseInfo response;
2854 HttpRequestHeaders request_headers;
2855 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
2856 callback_.callback()));
2857
2858 base::RunLoop().RunUntilIdle();
2859 // The session should now be marked as going away. Ensure that
2860 // while it is still alive, it is no longer active.
2861 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2862 EXPECT_FALSE(HasActiveSession(host_port_pair_));
2863 EXPECT_EQ(1u, session->GetNumActiveStreams());
2864
2865 // Verify that response headers on the migrated socket were delivered to the
2866 // stream.
2867 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
2868 EXPECT_EQ(200, response.headers->response_code());
2869
2870 stream.reset();
2871
2872 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2873 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2874 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
2875 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
2876 }
2877
2878 TEST_P(QuicStreamFactoryTest,
2879 MigrateSessionOnNetworkDisconnectedWithWriteErrorQueued) {
2880 MigrateSessionOnNotificationWithWriteErrorQueued(/*disconnected=*/true);
2881 }
2882
2883 TEST_P(QuicStreamFactoryTest,
2884 MigrateSessionOnNetworkMadeDefaultWithWriteErrorQueued) {
2885 MigrateSessionOnNotificationWithWriteErrorQueued(/*disconnected=*/true);
2886 }
2887
2888 void QuicStreamFactoryTestBase::
2889 MigrateSessionOnNotificationWithWriteErrorQueued(bool disconnected) {
2890 InitializeConnectionMigrationTest(
2891 {kDefaultNetworkForTests, kNewNetworkForTests});
2892 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2893 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2894 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2895
2896 MockQuicData socket_data;
2897 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2898 socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE);
2899 socket_data.AddSocketDataToFactory(&socket_factory_);
2900
2901 // Create request and QuicHttpStream.
2902 QuicStreamRequest request(factory_.get());
2903 EXPECT_EQ(ERR_IO_PENDING,
2904 request.Request(host_port_pair_, privacy_mode_,
2905 /*cert_verify_flags=*/0, url_, "GET", net_log_,
2906 callback_.callback()));
2907 EXPECT_EQ(OK, callback_.WaitForResult());
2908 std::unique_ptr<QuicHttpStream> stream = request.CreateStream();
2909 EXPECT_TRUE(stream.get());
2910
2911 // Cause QUIC stream to be created.
2912 HttpRequestInfo request_info;
2913 request_info.method = "GET";
2914 request_info.url = GURL("https://www.example.org/");
2915 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2916 net_log_, CompletionCallback()));
2917
2918 // Ensure that session is alive and active.
2919 QuicChromiumClientSession* session = GetActiveSession(host_port_pair_);
2920 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2921 EXPECT_TRUE(HasActiveSession(host_port_pair_));
2922
2923 // Set up second socket data provider that is used after
2924 // migration. The request is rewritten to this new socket, and the
2925 // response to the request is read on this new socket.
2926 MockQuicData socket_data1;
2927 socket_data1.AddWrite(
2928 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true));
2929 socket_data1.AddRead(
2930 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false));
2931 socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING);
2932 socket_data1.AddWrite(client_maker_.MakeAckAndRstPacket(
2933 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED, 1, 1, 1, true));
2934 socket_data1.AddSocketDataToFactory(&socket_factory_);
2935
2936 // Send GET request on stream. This should cause a write error,
2937 // which triggers a connection migration attempt. This will queue a
2938 // migration attempt in the message loop.
2939 HttpResponseInfo response;
2940 HttpRequestHeaders request_headers;
2941 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
2942 callback_.callback()));
2943
2944 // Now queue a network change notification in the message loop behind
2945 // the migration attempt.
2946 if (disconnected) {
2947 scoped_mock_network_change_notifier_->mock_network_change_notifier()
2948 ->QueueNetworkDisconnected(kDefaultNetworkForTests);
2949 } else {
2950 scoped_mock_network_change_notifier_->mock_network_change_notifier()
2951 ->QueueNetworkMadeDefault(kNewNetworkForTests);
2952 }
2953
2954 base::RunLoop().RunUntilIdle();
2955 // The session should now be marked as going away. Ensure that
2956 // while it is still alive, it is no longer active.
2957 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
2958 EXPECT_FALSE(HasActiveSession(host_port_pair_));
2959 EXPECT_EQ(1u, session->GetNumActiveStreams());
2960
2961 // Verify that response headers on the migrated socket were delivered to the
2962 // stream.
2963 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
2964 EXPECT_EQ(200, response.headers->response_code());
2965
2966 stream.reset();
2967
2968 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2969 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2970 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
2971 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
2972 }
2973
2640 TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyToBadSocket) { 2974 TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyToBadSocket) {
2641 // This simulates the case where we attempt to migrate to a new 2975 // This simulates the case where we attempt to migrate to a new
2642 // socket but the socket is unusable, such as an ipv4/ipv6 mismatch. 2976 // socket but the socket is unusable, such as an ipv4/ipv6 mismatch.
2643 InitializeConnectionMigrationTest( 2977 InitializeConnectionMigrationTest(
2644 {kDefaultNetworkForTests, kNewNetworkForTests}); 2978 {kDefaultNetworkForTests, kNewNetworkForTests});
2645 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 2979 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
2646 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2980 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2647 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 2981 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
2648 2982
2649 MockQuicData socket_data; 2983 MockQuicData socket_data;
(...skipping 2485 matching lines...) Expand 10 before | Expand all | Expand 10 after
5135 // Clear all cached states. 5469 // Clear all cached states.
5136 factory_->ClearCachedStatesInCryptoConfig( 5470 factory_->ClearCachedStatesInCryptoConfig(
5137 base::Callback<bool(const GURL&)>()); 5471 base::Callback<bool(const GURL&)>());
5138 EXPECT_TRUE(test_cases[0].state->certs().empty()); 5472 EXPECT_TRUE(test_cases[0].state->certs().empty());
5139 EXPECT_TRUE(test_cases[1].state->certs().empty()); 5473 EXPECT_TRUE(test_cases[1].state->certs().empty());
5140 EXPECT_TRUE(test_cases[2].state->certs().empty()); 5474 EXPECT_TRUE(test_cases[2].state->certs().empty());
5141 } 5475 }
5142 5476
5143 } // namespace test 5477 } // namespace test
5144 } // namespace net 5478 } // namespace net
OLDNEW
« net/quic/chromium/quic_chromium_client_session.cc ('K') | « net/quic/chromium/quic_stream_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698