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

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

Issue 295823002: Ensure races between pending and new SPDY streams don't violate session concurrency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to early return. Created 6 years, 7 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_session.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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 data.RunFor(4); 1038 data.RunFor(4);
1039 EXPECT_EQ(OK, delegate1.WaitForClose()); 1039 EXPECT_EQ(OK, delegate1.WaitForClose());
1040 EXPECT_EQ(kUploadData, delegate1.TakeReceivedData()); 1040 EXPECT_EQ(kUploadData, delegate1.TakeReceivedData());
1041 EXPECT_EQ(OK, delegate2.WaitForClose()); 1041 EXPECT_EQ(OK, delegate2.WaitForClose());
1042 EXPECT_EQ(kUploadData, delegate2.TakeReceivedData()); 1042 EXPECT_EQ(kUploadData, delegate2.TakeReceivedData());
1043 1043
1044 // Session was destroyed. 1044 // Session was destroyed.
1045 EXPECT_FALSE(session.get()); 1045 EXPECT_FALSE(session.get());
1046 } 1046 }
1047 1047
1048 // Verifies that an unstalled pending stream creation racing with a new stream
1049 // creation doesn't violate the maximum stream concurrency. Regression test for
1050 // crbug.com/373858.
1051 TEST_P(SpdySessionTest, UnstallRacesWithStreamCreation) {
1052 session_deps_.host_resolver->set_synchronous_mode(true);
1053
1054 MockRead reads[] = {
1055 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever.
1056 };
1057
1058 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
1059
1060 MockConnect connect_data(SYNCHRONOUS, OK);
1061 data.set_connect_data(connect_data);
1062 session_deps_.socket_factory->AddSocketDataProvider(&data);
1063
1064 CreateNetworkSession();
1065 base::WeakPtr<SpdySession> session =
1066 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1067
1068 // Fix max_concurrent_streams to allow for one open stream.
1069 session->max_concurrent_streams_ = 1;
1070
1071 // Create two streams: one synchronously, and one which stalls.
1072 GURL url(kDefaultURL);
1073 base::WeakPtr<SpdyStream> stream1 = CreateStreamSynchronously(
1074 SPDY_REQUEST_RESPONSE_STREAM, session, url, MEDIUM, BoundNetLog());
1075
1076 SpdyStreamRequest request2;
1077 TestCompletionCallback callback2;
1078 EXPECT_EQ(ERR_IO_PENDING,
1079 request2.StartRequest(SPDY_REQUEST_RESPONSE_STREAM,
1080 session,
1081 url,
1082 MEDIUM,
1083 BoundNetLog(),
1084 callback2.callback()));
1085
1086 EXPECT_EQ(1u, session->num_created_streams());
1087 EXPECT_EQ(1u, session->pending_create_stream_queue_size(MEDIUM));
1088
1089 // Cancel the first stream. A callback to unstall the second stream was
1090 // posted. Don't run it yet.
1091 stream1->Cancel();
1092
1093 EXPECT_EQ(0u, session->num_created_streams());
1094 EXPECT_EQ(0u, session->pending_create_stream_queue_size(MEDIUM));
1095
1096 // Create a third stream prior to the second stream's callback.
1097 base::WeakPtr<SpdyStream> stream3 = CreateStreamSynchronously(
1098 SPDY_REQUEST_RESPONSE_STREAM, session, url, MEDIUM, BoundNetLog());
1099
1100 EXPECT_EQ(1u, session->num_created_streams());
1101 EXPECT_EQ(0u, session->pending_create_stream_queue_size(MEDIUM));
1102
1103 // NOW run the message loop. The unstalled stream will re-stall itself.
1104 base::MessageLoop::current()->RunUntilIdle();
1105 EXPECT_EQ(1u, session->num_created_streams());
1106 EXPECT_EQ(1u, session->pending_create_stream_queue_size(MEDIUM));
1107
1108 // Cancel the third stream and run the message loop. Verify that the second
1109 // stream creation now completes.
1110 stream3->Cancel();
1111 base::MessageLoop::current()->RunUntilIdle();
1112
1113 EXPECT_EQ(1u, session->num_created_streams());
1114 EXPECT_EQ(0u, session->pending_create_stream_queue_size(MEDIUM));
1115 EXPECT_EQ(OK, callback2.WaitForResult());
1116 }
1117
1048 TEST_P(SpdySessionTest, DeleteExpiredPushStreams) { 1118 TEST_P(SpdySessionTest, DeleteExpiredPushStreams) {
1049 session_deps_.host_resolver->set_synchronous_mode(true); 1119 session_deps_.host_resolver->set_synchronous_mode(true);
1050 session_deps_.time_func = TheNearFuture; 1120 session_deps_.time_func = TheNearFuture;
1051 1121
1052 scoped_ptr<SpdyFrame> req( 1122 scoped_ptr<SpdyFrame> req(
1053 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); 1123 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true));
1054 scoped_ptr<SpdyFrame> rst( 1124 scoped_ptr<SpdyFrame> rst(
1055 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); 1125 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM));
1056 1126
1057 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( 1127 scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush(
(...skipping 3217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4275 RST_STREAM_PROTOCOL_ERROR)); 4345 RST_STREAM_PROTOCOL_ERROR));
4276 CHECK_EQ(STATUS_CODE_FRAME_SIZE_ERROR, 4346 CHECK_EQ(STATUS_CODE_FRAME_SIZE_ERROR,
4277 MapRstStreamStatusToProtocolError( 4347 MapRstStreamStatusToProtocolError(
4278 RST_STREAM_FRAME_SIZE_ERROR)); 4348 RST_STREAM_FRAME_SIZE_ERROR));
4279 CHECK_EQ(STATUS_CODE_ENHANCE_YOUR_CALM, 4349 CHECK_EQ(STATUS_CODE_ENHANCE_YOUR_CALM,
4280 MapRstStreamStatusToProtocolError( 4350 MapRstStreamStatusToProtocolError(
4281 RST_STREAM_ENHANCE_YOUR_CALM)); 4351 RST_STREAM_ENHANCE_YOUR_CALM));
4282 } 4352 }
4283 4353
4284 } // namespace net 4354 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698