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

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

Issue 3517012: Speculative fix for SpdySettingsStorage crasher. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Oops. Created 10 years, 2 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
« 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
6
5 #include "net/spdy/spdy_io_buffer.h" 7 #include "net/spdy/spdy_io_buffer.h"
6 #include "net/spdy/spdy_session.h"
7 #include "net/spdy/spdy_stream.h" 8 #include "net/spdy/spdy_stream.h"
8 #include "net/spdy/spdy_test_util.h" 9 #include "net/spdy/spdy_test_util.h"
9 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
10 11
11 namespace net { 12 namespace net {
12 13
13 // TODO(cbentzel): Expose compression setter/getter in public SpdySession 14 // TODO(cbentzel): Expose compression setter/getter in public SpdySession
14 // interface rather than going through all these contortions. 15 // interface rather than going through all these contortions.
15 class SpdySessionTest : public PlatformTest { 16 class SpdySessionTest : public PlatformTest {
16 public: 17 public:
17 static void TurnOffCompression() { 18 static void TurnOffCompression() {
18 spdy::SpdyFramer::set_enable_compression_default(false); 19 spdy::SpdyFramer::set_enable_compression_default(false);
19 } 20 }
20 }; 21 };
21 22
22 namespace { 23 namespace {
24
23 // Test the SpdyIOBuffer class. 25 // Test the SpdyIOBuffer class.
24 TEST_F(SpdySessionTest, SpdyIOBuffer) { 26 TEST_F(SpdySessionTest, SpdyIOBuffer) {
25 std::priority_queue<SpdyIOBuffer> queue_; 27 std::priority_queue<SpdyIOBuffer> queue_;
26 const size_t kQueueSize = 100; 28 const size_t kQueueSize = 100;
27 29
28 // Insert 100 items; pri 100 to 1. 30 // Insert 100 items; pri 100 to 1.
29 for (size_t index = 0; index < kQueueSize; ++index) { 31 for (size_t index = 0; index < kQueueSize; ++index) {
30 SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL); 32 SpdyIOBuffer buffer(new IOBuffer(), 0, kQueueSize - index, NULL);
31 queue_.push(buffer); 33 queue_.push(buffer);
32 } 34 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 BoundNetLog()); 110 BoundNetLog());
109 111
110 // Delete the first session. 112 // Delete the first session.
111 session = NULL; 113 session = NULL;
112 114
113 // Delete the second session. 115 // Delete the second session.
114 spdy_session_pool->Remove(session2); 116 spdy_session_pool->Remove(session2);
115 session2 = NULL; 117 session2 = NULL;
116 } 118 }
117 119
120 class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > {
121 public:
122 StreamReleaserCallback(SpdySession* session,
123 SpdyStream* first_stream)
124 : session_(session), first_stream_(first_stream) {}
125 ~StreamReleaserCallback() {}
126
127 int WaitForResult() { return callback_.WaitForResult(); }
128
129 virtual void RunWithParams(const Tuple1<int>& params) {
130 session_->CloseSessionOnError(ERR_FAILED, false);
Mike Belshe 2010/10/07 20:50:57 The Settings message will have been processed befo
131 session_ = NULL;
132 first_stream_->Cancel();
133 first_stream_ = NULL;
134 stream_->Cancel();
135 stream_ = NULL;
136 callback_.RunWithParams(params);
137 }
138
139 scoped_refptr<SpdyStream>* stream() { return &stream_; }
140
141 private:
142 scoped_refptr<SpdySession> session_;
143 scoped_refptr<SpdyStream> first_stream_;
144 scoped_refptr<SpdyStream> stream_;
145 TestCompletionCallback callback_;
146 };
147
148 // Start with max concurrent streams set to 1. Request two streams. Receive a
149 // settings frame setting max concurrent streams to 2. Have the callback
150 // release the stream, which releases its reference (the last) to the session.
151 // Make sure nothing blows up.
152 // http://crbug.com/57331
153 TEST_F(SpdySessionTest, OnSettings) {
154 SpdySessionDependencies session_deps;
155 session_deps.host_resolver->set_synchronous_mode(true);
156
157 spdy::SpdySettings new_settings;
158 spdy::SettingsFlagsAndId id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS);
159 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS);
160 const size_t max_concurrent_streams = 2;
161 new_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams));
162
163 // Set up the socket so we read a SETTINGS frame that raises max concurrent
164 // streams to 2.
165 MockConnect connect_data(false, OK);
166 scoped_ptr<spdy::SpdyFrame> settings_frame(
167 ConstructSpdySettings(new_settings));
168 MockRead reads[] = {
169 CreateMockRead(*settings_frame),
170 MockRead(false, 0, 0) // EOF
171 };
172
173 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
174 data.set_connect_data(connect_data);
175 session_deps.socket_factory->AddSocketDataProvider(&data);
176
177 SSLSocketDataProvider ssl(false, OK);
178 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
179
180 scoped_refptr<HttpNetworkSession> http_session(
181 SpdySessionDependencies::SpdyCreateSession(&session_deps));
182
183 const std::string kTestHost("www.foo.com");
184 const int kTestPort = 80;
185 HostPortPair test_host_port_pair(kTestHost, kTestPort);
186 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
187
188 // Initialize the SpdySettingsStorage with 1 max concurrent streams.
189 spdy::SpdySettings old_settings;
190 id.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST);
191 old_settings.push_back(spdy::SpdySetting(id, 1));
192 http_session->mutable_spdy_settings()->Set(
193 test_host_port_pair, old_settings);
194
195 // Create a session.
196 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
197 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
198 scoped_refptr<SpdySession> session =
199 spdy_session_pool->Get(pair, http_session->mutable_spdy_settings(),
200 BoundNetLog());
201 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
202
203 scoped_refptr<TCPSocketParams> tcp_params =
204 new TCPSocketParams(kTestHost, kTestPort, MEDIUM, GURL(), false);
205 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
206 EXPECT_EQ(OK,
207 connection->Init(test_host_port_pair.ToString(), tcp_params, MEDIUM,
208 NULL, http_session->tcp_socket_pool(),
209 BoundNetLog()));
210 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
211
212 // Create 2 streams. First will succeed. Second will be pending.
213 scoped_refptr<SpdyStream> spdy_stream1;
214 TestCompletionCallback callback1;
215 GURL url("http://www.google.com");
216 EXPECT_EQ(OK,
217 session->CreateStream(url,
218 MEDIUM, /* priority, not important */
219 &spdy_stream1,
220 BoundNetLog(),
221 &callback1));
222
223 StreamReleaserCallback stream_releaser(session, spdy_stream1);
224
225 ASSERT_EQ(ERR_IO_PENDING,
226 session->CreateStream(url,
227 MEDIUM, /* priority, not important */
228 stream_releaser.stream(),
229 BoundNetLog(),
230 &stream_releaser));
231
232 // Make sure |stream_releaser| holds the last refs.
233 session = NULL;
234 spdy_stream1 = NULL;
235
236 EXPECT_EQ(OK, stream_releaser.WaitForResult());
237 }
238
118 } // namespace 239 } // namespace
240
119 } // namespace net 241 } // 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