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

Side by Side Diff: net/spdy/spdy_network_transaction_spdy3_unittest.cc

Issue 11644088: SPDY - implement greedy approach to read all the data and process it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 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/spdy/spdy_network_transaction_spdy2_unittest.cc ('k') | net/spdy/spdy_session.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 (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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
15 #include "net/base/auth.h" 16 #include "net/base/auth.h"
17 #include "net/base/io_buffer.h"
16 #include "net/base/net_log_unittest.h" 18 #include "net/base/net_log_unittest.h"
19 #include "net/base/test_data_stream.h"
17 #include "net/base/upload_bytes_element_reader.h" 20 #include "net/base/upload_bytes_element_reader.h"
18 #include "net/base/upload_data_stream.h" 21 #include "net/base/upload_data_stream.h"
19 #include "net/base/upload_file_element_reader.h" 22 #include "net/base/upload_file_element_reader.h"
20 #include "net/http/http_network_session_peer.h" 23 #include "net/http/http_network_session_peer.h"
21 #include "net/http/http_transaction_unittest.h" 24 #include "net/http/http_transaction_unittest.h"
22 #include "net/socket/client_socket_pool_base.h" 25 #include "net/socket/client_socket_pool_base.h"
23 #include "net/spdy/buffered_spdy_framer.h" 26 #include "net/spdy/buffered_spdy_framer.h"
24 #include "net/spdy/spdy_http_stream.h" 27 #include "net/spdy/spdy_http_stream.h"
25 #include "net/spdy/spdy_http_utils.h" 28 #include "net/spdy/spdy_http_utils.h"
26 #include "net/spdy/spdy_session.h" 29 #include "net/spdy/spdy_session.h"
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 TestCompletionCallback callback1; 1042 TestCompletionCallback callback1;
1040 TestCompletionCallback callback2; 1043 TestCompletionCallback callback2;
1041 TestCompletionCallback callback3; 1044 TestCompletionCallback callback3;
1042 1045
1043 HttpRequestInfo httpreq1 = CreateGetRequest(); 1046 HttpRequestInfo httpreq1 = CreateGetRequest();
1044 HttpRequestInfo httpreq2 = CreateGetRequest(); 1047 HttpRequestInfo httpreq2 = CreateGetRequest();
1045 HttpRequestInfo httpreq3 = CreateGetRequest(); 1048 HttpRequestInfo httpreq3 = CreateGetRequest();
1046 1049
1047 out.rv = trans1->Start(&httpreq1, callback1.callback(), log); 1050 out.rv = trans1->Start(&httpreq1, callback1.callback(), log);
1048 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1051 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1049 // run transaction 1 through quickly to force a read of our SETTINGS 1052 // Run transaction 1 through quickly to force a read of our SETTINGS
1050 // frame 1053 // frame.
1051 out.rv = callback1.WaitForResult(); 1054 out.rv = callback1.WaitForResult();
1052 ASSERT_EQ(OK, out.rv); 1055 ASSERT_EQ(OK, out.rv);
1053 1056
1054 out.rv = trans2->Start(&httpreq2, callback2.callback(), log); 1057 out.rv = trans2->Start(&httpreq2, callback2.callback(), log);
1055 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1058 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1056 out.rv = trans3->Start(&httpreq3, callback3.callback(), log); 1059 out.rv = trans3->Start(&httpreq3, callback3.callback(), log);
1057 ASSERT_EQ(out.rv, ERR_IO_PENDING); 1060 ASSERT_EQ(out.rv, ERR_IO_PENDING);
1058 out.rv = callback2.WaitForResult(); 1061 out.rv = callback2.WaitForResult();
1059 ASSERT_EQ(OK, out.rv); 1062 ASSERT_EQ(OK, out.rv);
1060 EXPECT_EQ(7U, data.read_index()); // i.e. the third trans was queued 1063 EXPECT_EQ(7U, data.read_index()); // i.e. the third trans was queued
(...skipping 3436 matching lines...) Expand 10 before | Expand all | Expand 10 after
4497 MessageLoop::current()->RunUntilIdle(); 4500 MessageLoop::current()->RunUntilIdle();
4498 4501
4499 // Verify that we consumed all test data. 4502 // Verify that we consumed all test data.
4500 helper.VerifyDataConsumed(); 4503 helper.VerifyDataConsumed();
4501 4504
4502 EXPECT_EQ(OK, out.rv); 4505 EXPECT_EQ(OK, out.rv);
4503 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 4506 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
4504 EXPECT_EQ("messagemessagemessagemessage", out.response_data); 4507 EXPECT_EQ("messagemessagemessagemessage", out.response_data);
4505 } 4508 }
4506 4509
4510 // Verify the case where SpdySession reads all the data synchronously without
4511 // yielding.
Ryan Hamilton 2013/01/19 00:32:13 How does this test verify that the session yields?
ramant (doing other things) 2013/02/04 18:30:46 With out DeterminsticSocketData changes and TaskOb
4512 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedSyncRead) {
4513 BufferedSpdyFramer framer(3, false);
4514
4515 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
4516 MockWrite writes[] = { CreateMockWrite(*req) };
4517
4518 scoped_ptr<SpdyFrame> syn_reply(
4519 ConstructSpdyGetSynReply(NULL, 0, 1));
4520 syn_reply->set_flags(CONTROL_FLAG_NONE); // Turn off FIN bit.
4521
4522 const int kPayloadSize = 1600;
4523 net::TestDataStream test_stream;
Ryan Hamilton 2013/01/19 00:32:13 nit: no need for test::, I think. (And in the nex
ramant (doing other things) 2013/02/04 18:30:46 Made all these changes in SpdySession unit tests.
4524 scoped_refptr<net::IOBuffer> payload(new net::IOBuffer(kPayloadSize));
4525 test_stream.GetBytes(payload->data(), kPayloadSize);
4526 char* payload_data = payload->data();
Ryan Hamilton 2013/01/19 00:32:13 nit: move this line above the previous, and use pa
ramant (doing other things) 2013/02/04 18:30:46 Made all these changes in SpdySession unit tests.
4527 std::string payload_content(payload_data, kPayloadSize);
4528 scoped_ptr<SpdyFrame> data_frame(
4529 framer.CreateDataFrame(1, payload_data, kPayloadSize, DATA_FLAG_FIN));
4530 const SpdyFrame* frames[2] = {
4531 syn_reply.get(),
4532 data_frame.get()
4533 };
4534 char combined_frames[5000];
4535 int combined_frames_len =
4536 CombineFrames(frames, arraysize(frames),
4537 combined_frames, arraysize(combined_frames));
4538
4539 MockRead reads[] = {
4540 MockRead(ASYNC, combined_frames, combined_frames_len),
4541 MockRead(ASYNC, 0, 0) // EOF
4542 };
4543
4544 DelayedSocketData data(1, reads, arraysize(reads),
4545 writes, arraysize(writes));
4546
4547 NormalSpdyTransactionHelper helper(CreateGetRequest(),
4548 BoundNetLog(), GetParam(), NULL);
4549 helper.RunPreTestSetup();
4550 helper.AddData(&data);
4551 HttpNetworkTransaction* trans = helper.trans();
4552
4553 TestCompletionCallback callback;
4554 int rv = trans->Start(
4555 &CreateGetRequest(), callback.callback(), BoundNetLog());
4556 EXPECT_EQ(ERR_IO_PENDING, rv);
4557
4558 TransactionHelperResult out = helper.output();
4559 out.rv = callback.WaitForResult();
4560 EXPECT_EQ(out.rv, OK);
4561
4562 const HttpResponseInfo* response = trans->GetResponseInfo();
4563 EXPECT_TRUE(response->headers != NULL);
4564 EXPECT_TRUE(response->was_fetched_via_spdy);
4565 out.status_line = response->headers->GetStatusLine();
4566 out.response_info = *response; // Make a copy so we can verify.
4567
4568 // Read Data.
4569 TestCompletionCallback read_callback;
4570
4571 std::string content;
4572 int reads_completed = 0;
4573 do {
4574 // Read data in chunks.
4575 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kPayloadSize));
4576 rv = trans->Read(buf, kPayloadSize, read_callback.callback());
Ryan Hamilton 2013/01/19 00:32:13 nit: I would just do ASSERT_LE(0, rv);
ramant (doing other things) 2013/02/04 18:30:46 Deleted this test.
4577 if (rv > 0) {
4578 content.append(buf->data(), rv);
4579 } else if (rv < 0) {
4580 FAIL() << "Unexpected read error: " << rv;
4581 }
4582 reads_completed++;
4583 } while (rv > 0);
4584
4585 out.response_data.swap(content);
4586
4587 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the
4588 // MockClientSocketFactory) are still alive.
4589 MessageLoop::current()->RunUntilIdle();
Ryan Hamilton 2013/01/19 00:32:13 Can you do this as the last thing line in this tes
ramant (doing other things) 2013/02/04 18:30:46 Deleted this test.
4590
4591 // Verify that we consumed all test data.
4592 helper.VerifyDataConsumed();
4593
4594 EXPECT_EQ(OK, out.rv);
4595 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
4596 EXPECT_EQ(payload_content, out.response_data);
4597 }
4598
4599 // Verify the case where SpdySession reads kMaxReadBytes data synchronously and
4600 // then reads more data after yielding.
Ryan Hamilton 2013/01/19 00:32:13 I don't think I see how this shows that the sessio
ramant (doing other things) 2013/02/04 18:30:46 Wrote the new unit tests.
4601 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedASyncRead) {
4602 BufferedSpdyFramer framer(3, false);
4603
4604 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
4605 MockWrite writes[] = { CreateMockWrite(*req) };
4606
4607 scoped_ptr<SpdyFrame> syn_reply(
4608 ConstructSpdyGetSynReply(NULL, 0, 1));
4609 syn_reply->set_flags(CONTROL_FLAG_NONE); // Turn off FIN bit.
4610
4611 const int kPayloadSize = kMaxReadBytes * 2;
4612 net::TestDataStream test_stream;
4613 scoped_refptr<net::IOBuffer> payload(new net::IOBuffer(kPayloadSize));
4614 test_stream.GetBytes(payload->data(), kPayloadSize);
4615 char* payload_data = payload->data();
4616 std::string payload_content(payload_data, kPayloadSize);
4617 scoped_ptr<SpdyFrame> data_frame(
4618 framer.CreateDataFrame(1, payload_data, kPayloadSize, DATA_FLAG_FIN));
4619 const SpdyFrame* frames[2] = {
4620 syn_reply.get(),
4621 data_frame.get()
4622 };
4623 int heap_size = kPayloadSize * 2;
4624 scoped_ptr<char, base::FreeDeleter>
4625 combined_frames(static_cast<char*>(malloc(heap_size)));
4626 CHECK(combined_frames.get());
4627 int combined_frames_len =
4628 CombineFrames(frames, arraysize(frames),
4629 combined_frames.get(), heap_size);
4630
4631 MockRead reads[] = {
4632 MockRead(ASYNC, combined_frames.get(), combined_frames_len),
4633 MockRead(ASYNC, 0, 0) // EOF
4634 };
4635
4636 DelayedSocketData data(1, reads, arraysize(reads),
4637 writes, arraysize(writes));
4638
4639 NormalSpdyTransactionHelper helper(CreateGetRequest(),
4640 BoundNetLog(), GetParam(), NULL);
4641 helper.RunPreTestSetup();
4642 helper.AddData(&data);
4643 HttpNetworkTransaction* trans = helper.trans();
4644
4645 TestCompletionCallback callback;
4646 int rv = trans->Start(
4647 &CreateGetRequest(), callback.callback(), BoundNetLog());
4648 EXPECT_EQ(ERR_IO_PENDING, rv);
4649
4650 TransactionHelperResult out = helper.output();
4651 out.rv = callback.WaitForResult();
4652 EXPECT_EQ(out.rv, OK);
4653
4654 const HttpResponseInfo* response = trans->GetResponseInfo();
4655 EXPECT_TRUE(response->headers != NULL);
4656 EXPECT_TRUE(response->was_fetched_via_spdy);
4657 out.status_line = response->headers->GetStatusLine();
4658 out.response_info = *response; // Make a copy so we can verify.
4659
4660 // Read Data.
4661 TestCompletionCallback read_callback;
4662
4663 std::string content;
4664 int reads_completed = 0;
4665 do {
4666 // Read data in chunks.
4667 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kMaxReadBytes));
4668 rv = trans->Read(buf, kMaxReadBytes, read_callback.callback());
4669 if (rv > 0) {
4670 content.append(buf->data(), rv);
4671 } else if (rv < 0) {
4672 FAIL() << "Unexpected read error: " << rv;
4673 }
4674 reads_completed++;
4675 } while (rv > 0);
4676
4677 out.response_data.swap(content);
4678
4679 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the
4680 // MockClientSocketFactory) are still alive.
4681 MessageLoop::current()->RunUntilIdle();
4682
4683 // Verify that we consumed all test data.
4684 helper.VerifyDataConsumed();
4685
4686 EXPECT_EQ(OK, out.rv);
4687 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
4688 EXPECT_EQ(payload_content, out.response_data);
4689 }
4690
4507 // Verify the case where we buffer data and close the connection. 4691 // Verify the case where we buffer data and close the connection.
4508 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedClosed) { 4692 TEST_P(SpdyNetworkTransactionSpdy3Test, BufferedClosed) {
4509 BufferedSpdyFramer framer(3, false); 4693 BufferedSpdyFramer framer(3, false);
4510 4694
4511 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 4695 scoped_ptr<SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
4512 MockWrite writes[] = { CreateMockWrite(*req) }; 4696 MockWrite writes[] = { CreateMockWrite(*req) };
4513 4697
4514 // All data frames in a single read. 4698 // All data frames in a single read.
4515 // NOTE: We don't FIN the stream. 4699 // NOTE: We don't FIN the stream.
4516 scoped_ptr<SpdyFrame> data_frame( 4700 scoped_ptr<SpdyFrame> data_frame(
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after
6357 // And now we can allow everything else to run to completion. 6541 // And now we can allow everything else to run to completion.
6358 data.SetStop(10); 6542 data.SetStop(10);
6359 data.Run(); 6543 data.Run();
6360 EXPECT_EQ(OK, callback2.WaitForResult()); 6544 EXPECT_EQ(OK, callback2.WaitForResult());
6361 EXPECT_EQ(OK, callback3.WaitForResult()); 6545 EXPECT_EQ(OK, callback3.WaitForResult());
6362 6546
6363 helper.VerifyDataConsumed(); 6547 helper.VerifyDataConsumed();
6364 } 6548 }
6365 6549
6366 } // namespace net 6550 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_spdy2_unittest.cc ('k') | net/spdy/spdy_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698