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

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

Issue 1061853002: Emit session-level WINDOW_UPDATEs less frequently. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test and loads of plumbing. Created 5 years, 8 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 4393 matching lines...) Expand 10 before | Expand all | Expand 10 after
4404 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( 4404 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings(
4405 host_port_pair).size()); 4405 host_port_pair).size());
4406 4406
4407 // Construct the initial SETTINGS frame. 4407 // Construct the initial SETTINGS frame.
4408 SettingsMap initial_settings; 4408 SettingsMap initial_settings;
4409 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = 4409 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] =
4410 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); 4410 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams);
4411 scoped_ptr<SpdyFrame> initial_settings_frame( 4411 scoped_ptr<SpdyFrame> initial_settings_frame(
4412 spdy_util_.ConstructSpdySettings(initial_settings)); 4412 spdy_util_.ConstructSpdySettings(initial_settings));
4413 4413
4414 // Construct the initial window update.
4415 scoped_ptr<SpdyFrame> initial_window_update(
4416 spdy_util_.ConstructSpdyWindowUpdate(
4417 kSessionFlowControlStreamId,
4418 kDefaultInitialRecvWindowSize -
4419 SpdySession::GetInitialWindowSize(GetParam().protocol)));
Ryan Hamilton 2015/04/07 14:56:40 Can you explain why this changed? Since this test
Bence 2015/04/07 20:21:38 Absolutely. Before this change, the session level
4420
4421 // Construct the persisted SETTINGS frame. 4414 // Construct the persisted SETTINGS frame.
4422 const SettingsMap& settings = 4415 const SettingsMap& settings =
4423 spdy_session_pool->http_server_properties()->GetSpdySettings( 4416 spdy_session_pool->http_server_properties()->GetSpdySettings(
4424 host_port_pair); 4417 host_port_pair);
4425 scoped_ptr<SpdyFrame> settings_frame( 4418 scoped_ptr<SpdyFrame> settings_frame(
4426 spdy_util_.ConstructSpdySettings(settings)); 4419 spdy_util_.ConstructSpdySettings(settings));
4427 4420
4428 // Construct the request. 4421 // Construct the request.
4429 scoped_ptr<SpdyFrame> req( 4422 scoped_ptr<SpdyFrame> req(
4430 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 4423 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
4431 4424
4432 std::vector<MockWrite> writes; 4425 std::vector<MockWrite> writes;
4433 if ((GetParam().protocol >= kProtoSPDY4MinimumVersion) && 4426 if ((GetParam().protocol >= kProtoSPDY4MinimumVersion) &&
4434 (GetParam().protocol <= kProtoSPDY4MaximumVersion)) { 4427 (GetParam().protocol <= kProtoSPDY4MaximumVersion)) {
4435 writes.push_back( 4428 writes.push_back(
4436 MockWrite(ASYNC, 4429 MockWrite(ASYNC,
4437 kHttp2ConnectionHeaderPrefix, 4430 kHttp2ConnectionHeaderPrefix,
4438 kHttp2ConnectionHeaderPrefixSize)); 4431 kHttp2ConnectionHeaderPrefixSize));
4439 } 4432 }
4440 writes.push_back(CreateMockWrite(*initial_settings_frame)); 4433 writes.push_back(CreateMockWrite(*initial_settings_frame));
4441 if (GetParam().protocol >= kProtoSPDY31) {
4442 writes.push_back(CreateMockWrite(*initial_window_update));
4443 }
4444 writes.push_back(CreateMockWrite(*settings_frame)); 4434 writes.push_back(CreateMockWrite(*settings_frame));
4445 writes.push_back(CreateMockWrite(*req)); 4435 writes.push_back(CreateMockWrite(*req));
4446 4436
4447 // Construct the reply. 4437 // Construct the reply.
4448 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); 4438 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock());
4449 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; 4439 (*reply_headers)[spdy_util_.GetStatusKey()] = "200";
4450 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; 4440 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1";
4451 scoped_ptr<SpdyFrame> reply( 4441 scoped_ptr<SpdyFrame> reply(
4452 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); 4442 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass()));
4453 4443
(...skipping 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after
6140 data.RunFor(1); 6130 data.RunFor(1);
6141 6131
6142 rv = callback.WaitForResult(); 6132 rv = callback.WaitForResult();
6143 EXPECT_EQ(OK, rv); 6133 EXPECT_EQ(OK, rv);
6144 6134
6145 helper.VerifyDataConsumed(); 6135 helper.VerifyDataConsumed();
6146 } 6136 }
6147 6137
6148 // Test that received data frames and sent WINDOW_UPDATE frames change 6138 // Test that received data frames and sent WINDOW_UPDATE frames change
6149 // the recv_window_size_ correctly. 6139 // the recv_window_size_ correctly.
6150 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { 6140 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) {
Ryan Hamilton 2015/04/07 14:56:40 Boy, this test is *much* better now!
Bence 2015/04/07 20:21:38 Yup, I feel the same way. Thanks for your guidanc
6151 const int32 initial_window_size = 6141 // Session level window size that is more than twice the default 65536 or
6152 SpdySession::GetInitialWindowSize(GetParam().protocol); 6142 // 65535 bytes so that an initial window update is sent.
6153 // Amount of body required to trigger a sent window update. 6143 const int32 session_max_recv_window_size = 132 * 1024;
Ryan Hamilton 2015/04/07 14:56:40 If you want this to be, more than 2x the default,
Bence 2015/04/07 20:21:38 Sorry, there are many requirements here that neces
6154 const size_t kTargetSize = initial_window_size / 2 + 1; 6144 // Stream level window size that is more than the default 65536 or 65535
6145 // bytes but less than the session level window size.
6146 const int32 stream_initial_recv_window_size = 100 * 1024;
Ryan Hamilton 2015/04/07 14:56:40 Ditto.
Bence 2015/04/07 20:21:38 Done.
6147 // Amount of body to be sent. Has to less than or equal to both window sizes
6148 // so that we do not run out of receiving window, and greater than half of
6149 // them so that it triggers both a session level and a stream level window
6150 // update frame.
6151 const size_t kTargetSize = 72 * 1024;
Ryan Hamilton 2015/04/07 14:56:40 How 'bout something like stream_size + session_siz
Bence 2015/04/07 20:21:38 Done.
6155 6152
6153 SettingsMap initial_settings;
6154 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] =
6155 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams);
6156 initial_settings[SETTINGS_INITIAL_WINDOW_SIZE] = SettingsFlagsAndValue(
6157 SETTINGS_FLAG_NONE, stream_initial_recv_window_size);
6158 scoped_ptr<SpdyFrame> initial_settings_frame(
6159 spdy_util_.ConstructSpdySettings(initial_settings));
6160 scoped_ptr<SpdyFrame> initial_window_update(
6161 spdy_util_.ConstructSpdyWindowUpdate(
6162 kSessionFlowControlStreamId,
6163 session_max_recv_window_size -
6164 SpdySession::GetInitialWindowSize(GetParam().protocol)));
6156 scoped_ptr<SpdyFrame> req( 6165 scoped_ptr<SpdyFrame> req(
6157 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); 6166 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true));
6167 // WINDOW_UPDATEs are sent for the smaller multiple of 4 kB exceeding half the
6168 // respective windows, because DATA frames constructed below are 4 kB each.
6158 scoped_ptr<SpdyFrame> session_window_update( 6169 scoped_ptr<SpdyFrame> session_window_update(
6159 spdy_util_.ConstructSpdyWindowUpdate(0, kTargetSize)); 6170 spdy_util_.ConstructSpdyWindowUpdate(0, 68 * 1024));
6160 scoped_ptr<SpdyFrame> window_update( 6171 scoped_ptr<SpdyFrame> stream_window_update(
6161 spdy_util_.ConstructSpdyWindowUpdate(1, kTargetSize)); 6172 spdy_util_.ConstructSpdyWindowUpdate(1, 52 * 1024));
Ryan Hamilton 2015/04/07 14:56:40 more magic numbers make this test hard to reason a
Bence 2015/04/07 20:21:37 Done.
6162 6173
6163 std::vector<MockWrite> writes; 6174 std::vector<MockWrite> writes;
6175 if ((GetParam().protocol >= kProtoSPDY4MinimumVersion) &&
6176 (GetParam().protocol <= kProtoSPDY4MaximumVersion)) {
6177 writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix,
6178 kHttp2ConnectionHeaderPrefixSize, 0));
6179 }
6180 writes.push_back(CreateMockWrite(*initial_settings_frame));
6181 writes.push_back(CreateMockWrite(*initial_window_update));
6164 writes.push_back(CreateMockWrite(*req)); 6182 writes.push_back(CreateMockWrite(*req));
6165 if (GetParam().protocol >= kProtoSPDY31) 6183 writes.push_back(CreateMockWrite(*session_window_update));
6166 writes.push_back(CreateMockWrite(*session_window_update)); 6184 writes.push_back(CreateMockWrite(*stream_window_update));
6167 writes.push_back(CreateMockWrite(*window_update));
6168 6185
6169 std::vector<MockRead> reads; 6186 std::vector<MockRead> reads;
6170 scoped_ptr<SpdyFrame> resp( 6187 scoped_ptr<SpdyFrame> resp(
6171 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); 6188 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
6172 reads.push_back(CreateMockRead(*resp)); 6189 reads.push_back(CreateMockRead(*resp));
6173 6190
6174 ScopedVector<SpdyFrame> body_frames; 6191 ScopedVector<SpdyFrame> body_frames;
6175 const std::string body_data(4096, 'x'); 6192 const std::string body_data(4096, 'x');
6176 for (size_t remaining = kTargetSize; remaining != 0;) { 6193 for (size_t remaining = kTargetSize; remaining != 0;) {
6177 size_t frame_size = std::min(remaining, body_data.size()); 6194 size_t frame_size = std::min(remaining, body_data.size());
6178 body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( 6195 body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame(
6179 1, body_data.data(), frame_size, false)); 6196 1, body_data.data(), frame_size, false));
6180 reads.push_back(CreateMockRead(*body_frames.back())); 6197 reads.push_back(CreateMockRead(*body_frames.back()));
6181 remaining -= frame_size; 6198 remaining -= frame_size;
6182 } 6199 }
6183 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. 6200 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield.
6184 6201
6185 DelayedSocketData data(1, vector_as_array(&reads), reads.size(), 6202 DelayedSocketData data(2, vector_as_array(&reads), reads.size(),
6186 vector_as_array(&writes), writes.size()); 6203 vector_as_array(&writes), writes.size());
6187 6204
6188 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, 6205 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY,
6189 BoundNetLog(), GetParam(), NULL); 6206 BoundNetLog(), GetParam(), NULL);
6190 helper.AddData(&data); 6207 helper.AddData(&data);
6191 helper.RunPreTestSetup(); 6208 helper.RunPreTestSetup();
6209
6210 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool();
6211 SpdySessionPoolPeer pool_peer(spdy_session_pool);
6212 pool_peer.SetEnableSendingInitialData(true);
6213 pool_peer.SetSessionMaxRecvWindowSize(session_max_recv_window_size);
6214 pool_peer.SetStreamInitialRecvWindowSize(stream_initial_recv_window_size);
Ryan Hamilton 2015/04/07 14:56:40 I think this highlights a mismatch in vocabulary h
Bence 2015/04/07 20:21:38 Great idea. I am changing this method and every r
6215
6192 HttpNetworkTransaction* trans = helper.trans(); 6216 HttpNetworkTransaction* trans = helper.trans();
6193
6194 TestCompletionCallback callback; 6217 TestCompletionCallback callback;
6195 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); 6218 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog());
6196 6219
6197 EXPECT_EQ(ERR_IO_PENDING, rv); 6220 EXPECT_EQ(ERR_IO_PENDING, rv);
6198 rv = callback.WaitForResult(); 6221 rv = callback.WaitForResult();
6199 EXPECT_EQ(OK, rv); 6222 EXPECT_EQ(OK, rv);
6200 6223
6201 SpdyHttpStream* stream = 6224 SpdyHttpStream* stream =
6202 static_cast<SpdyHttpStream*>(trans->stream_.get()); 6225 static_cast<SpdyHttpStream*>(trans->stream_.get());
6203 ASSERT_TRUE(stream != NULL); 6226 ASSERT_TRUE(stream != NULL);
6204 ASSERT_TRUE(stream->stream() != NULL); 6227 ASSERT_TRUE(stream->stream() != NULL);
6205 6228
6206 // All data has been read, but not consumed. The window reflects this. 6229 // All data has been read, but not consumed. The window reflects this.
6207 EXPECT_EQ(static_cast<int>(initial_window_size - kTargetSize), 6230 EXPECT_EQ(static_cast<int>(stream_initial_recv_window_size - kTargetSize),
6208 stream->stream()->recv_window_size()); 6231 stream->stream()->recv_window_size());
6209 6232
6210 const HttpResponseInfo* response = trans->GetResponseInfo(); 6233 const HttpResponseInfo* response = trans->GetResponseInfo();
6211 ASSERT_TRUE(response != NULL); 6234 ASSERT_TRUE(response != NULL);
6212 ASSERT_TRUE(response->headers.get() != NULL); 6235 ASSERT_TRUE(response->headers.get() != NULL);
6213 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 6236 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
6214 EXPECT_TRUE(response->was_fetched_via_spdy); 6237 EXPECT_TRUE(response->was_fetched_via_spdy);
6215 6238
6216 // Issue a read which will cause a WINDOW_UPDATE to be sent and window 6239 // Issue a read which will cause a WINDOW_UPDATE to be sent and window
6217 // size increased to default. 6240 // size increased to default.
6218 scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); 6241 scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize));
6219 EXPECT_EQ(static_cast<int>(kTargetSize), 6242 EXPECT_EQ(static_cast<int>(kTargetSize),
6220 trans->Read(buf.get(), kTargetSize, CompletionCallback())); 6243 trans->Read(buf.get(), kTargetSize, CompletionCallback()));
6221 EXPECT_EQ(static_cast<int>(initial_window_size), 6244 EXPECT_EQ(static_cast<int>(stream_initial_recv_window_size),
6222 stream->stream()->recv_window_size()); 6245 stream->stream()->recv_window_size());
6223 EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); 6246 EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x')));
6224 6247
6225 // Allow scheduled WINDOW_UPDATE frames to write. 6248 // Allow scheduled WINDOW_UPDATE frames to write.
6226 base::RunLoop().RunUntilIdle(); 6249 base::RunLoop().RunUntilIdle();
6227 helper.VerifyDataConsumed(); 6250 helper.VerifyDataConsumed();
6228 } 6251 }
6229 6252
6230 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. 6253 // Test that WINDOW_UPDATE frame causing overflow is handled correctly.
6231 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { 6254 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) {
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
6812 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { 6835 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) {
6813 scoped_ptr<SSLSocketDataProvider> ssl_provider( 6836 scoped_ptr<SSLSocketDataProvider> ssl_provider(
6814 new SSLSocketDataProvider(ASYNC, OK)); 6837 new SSLSocketDataProvider(ASYNC, OK));
6815 // Set to TLS_RSA_WITH_NULL_MD5 6838 // Set to TLS_RSA_WITH_NULL_MD5
6816 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); 6839 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status);
6817 6840
6818 RunTLSUsageCheckTest(ssl_provider.Pass()); 6841 RunTLSUsageCheckTest(ssl_provider.Pass());
6819 } 6842 }
6820 6843
6821 } // namespace net 6844 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698