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

Side by Side Diff: net/socket/client_socket_pool_base_unittest.cc

Issue 5549001: Fix preconnect crash when we hit max socket limit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO, fix lint error. Created 10 years 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/socket/client_socket_pool_base.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/socket/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/platform_thread.h" 10 #include "base/platform_thread.h"
(...skipping 3007 matching lines...) Expand 10 before | Expand all | Expand 10 after
3018 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3018 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3019 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); 3019 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a"));
3020 3020
3021 ASSERT_EQ(OK, callback1.WaitForResult()); 3021 ASSERT_EQ(OK, callback1.WaitForResult());
3022 3022
3023 handle1.Reset(); 3023 handle1.Reset();
3024 3024
3025 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a")); 3025 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a"));
3026 } 3026 }
3027 3027
3028 // http://crbug.com/64940 regression test.
3029 TEST_F(ClientSocketPoolBaseTest, PreconnectClosesIdleSocketRemovesGroup) {
3030 const int kMaxTotalSockets = 3;
3031 const int kMaxSocketsPerGroup = 2;
3032 CreatePool(kMaxTotalSockets, kMaxSocketsPerGroup);
3033 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
3034
3035 // Note that group name ordering matters here. "a" comes before "b", so
3036 // CloseOneIdleSocket() will try to close "a"'s idle socket.
3037
3038 // Set up one idle socket in "a".
3039 ClientSocketHandle handle1;
3040 TestCompletionCallback callback1;
3041 EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a",
3042 params_,
3043 kDefaultPriority,
3044 &callback1,
3045 pool_.get(),
3046 BoundNetLog()));
3047
3048 ASSERT_EQ(OK, callback1.WaitForResult());
3049 handle1.Reset();
3050 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a"));
3051
3052 // Set up two active sockets in "b".
3053 ClientSocketHandle handle2;
3054 TestCompletionCallback callback2;
3055 EXPECT_EQ(ERR_IO_PENDING, handle1.Init("b",
3056 params_,
3057 kDefaultPriority,
3058 &callback1,
3059 pool_.get(),
3060 BoundNetLog()));
3061 EXPECT_EQ(ERR_IO_PENDING, handle2.Init("b",
3062 params_,
3063 kDefaultPriority,
3064 &callback2,
3065 pool_.get(),
3066 BoundNetLog()));
3067
3068 ASSERT_EQ(OK, callback1.WaitForResult());
3069 ASSERT_EQ(OK, callback2.WaitForResult());
3070 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("b"));
3071 EXPECT_EQ(2, pool_->NumActiveSocketsInGroup("b"));
3072
3073 // Now we have 1 idle socket in "a" and 2 active sockets in "b". This means
3074 // we've maxed out on sockets, since we set |kMaxTotalSockets| to 3.
3075 // Requesting 2 preconnected sockets for "a" should fail to allocate any more
3076 // sockets for "a", and "b" should still have 2 active sockets.
3077
3078 pool_->RequestSockets("a", &params_, 2, BoundNetLog());
3079 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a"));
3080 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a"));
3081 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("a"));
3082 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("b"));
3083 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("b"));
3084 EXPECT_EQ(2, pool_->NumActiveSocketsInGroup("b"));
3085
3086 // Now release the 2 active sockets for "b". This will give us 1 idle socket
3087 // in "a" and 2 idle sockets in "b". Requesting 2 preconnected sockets for
3088 // "a" should result in closing 1 for "b".
3089 handle1.Reset();
3090 handle2.Reset();
3091 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("b"));
3092 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("b"));
3093
3094 pool_->RequestSockets("a", &params_, 2, BoundNetLog());
3095 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3096 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("a"));
3097 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("a"));
3098 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("b"));
3099 EXPECT_EQ(1, pool_->IdleSocketCountInGroup("b"));
3100 EXPECT_EQ(0, pool_->NumActiveSocketsInGroup("b"));
3101 }
3102
3028 } // namespace 3103 } // namespace
3029 3104
3030 } // namespace net 3105 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698