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

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

Issue 196053: When converting between units of time or data types of different precision,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 | « base/timer.cc ('k') | net/socket/socket_test_util.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/platform_thread.h" 9 #include "base/platform_thread.h"
10 #include "base/scoped_vector.h" 10 #include "base/scoped_vector.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 AddressList ignored; 136 AddressList ignored;
137 client_socket_factory_->CreateTCPClientSocket(ignored); 137 client_socket_factory_->CreateTCPClientSocket(ignored);
138 set_socket(new MockClientSocket()); 138 set_socket(new MockClientSocket());
139 switch (job_type_) { 139 switch (job_type_) {
140 case kMockJob: 140 case kMockJob:
141 return DoConnect(true /* successful */, false /* sync */); 141 return DoConnect(true /* successful */, false /* sync */);
142 case kMockFailingJob: 142 case kMockFailingJob:
143 return DoConnect(false /* error */, false /* sync */); 143 return DoConnect(false /* error */, false /* sync */);
144 case kMockPendingJob: 144 case kMockPendingJob:
145 set_load_state(LOAD_STATE_CONNECTING); 145 set_load_state(LOAD_STATE_CONNECTING);
146 MessageLoop::current()->PostTask( 146 MessageLoop::current()->PostDelayedTask(
147 FROM_HERE, 147 FROM_HERE,
148 method_factory_.NewRunnableMethod( 148 method_factory_.NewRunnableMethod(
149 &TestConnectJob::DoConnect, 149 &TestConnectJob::DoConnect,
150 true /* successful */, 150 true /* successful */,
151 true /* async */)); 151 true /* async */),
152 2);
152 return ERR_IO_PENDING; 153 return ERR_IO_PENDING;
153 case kMockPendingFailingJob: 154 case kMockPendingFailingJob:
154 set_load_state(LOAD_STATE_CONNECTING); 155 set_load_state(LOAD_STATE_CONNECTING);
155 MessageLoop::current()->PostTask( 156 MessageLoop::current()->PostDelayedTask(
156 FROM_HERE, 157 FROM_HERE,
157 method_factory_.NewRunnableMethod( 158 method_factory_.NewRunnableMethod(
158 &TestConnectJob::DoConnect, 159 &TestConnectJob::DoConnect,
159 false /* error */, 160 false /* error */,
160 true /* async */)); 161 true /* async */),
162 2);
161 return ERR_IO_PENDING; 163 return ERR_IO_PENDING;
162 case kMockWaitingJob: 164 case kMockWaitingJob:
163 client_socket_factory_->WaitForSignal(this); 165 client_socket_factory_->WaitForSignal(this);
164 waiting_success_ = true; 166 waiting_success_ = true;
165 return ERR_IO_PENDING; 167 return ERR_IO_PENDING;
166 case kMockAdvancingLoadStateJob: 168 case kMockAdvancingLoadStateJob:
167 MessageLoop::current()->PostTask( 169 MessageLoop::current()->PostDelayedTask(
168 FROM_HERE, 170 FROM_HERE,
169 method_factory_.NewRunnableMethod( 171 method_factory_.NewRunnableMethod(
170 &TestConnectJob::AdvanceLoadState, load_state_)); 172 &TestConnectJob::AdvanceLoadState, load_state_),
173 2);
171 return ERR_IO_PENDING; 174 return ERR_IO_PENDING;
172 default: 175 default:
173 NOTREACHED(); 176 NOTREACHED();
174 set_socket(NULL); 177 set_socket(NULL);
175 return ERR_FAILED; 178 return ERR_FAILED;
176 } 179 }
177 } 180 }
178 181
179 void set_load_state(LoadState load_state) { load_state_ = load_state; } 182 void set_load_state(LoadState load_state) { load_state_ = load_state; }
180 183
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 TEST_F(ClientSocketPoolBaseTest, TotalLimitCountsConnectingSockets) { 713 TEST_F(ClientSocketPoolBaseTest, TotalLimitCountsConnectingSockets) {
711 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); 714 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup);
712 715
713 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); 716 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority));
714 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority)); 717 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority));
715 EXPECT_EQ(OK, StartRequest("c", kDefaultPriority)); 718 EXPECT_EQ(OK, StartRequest("c", kDefaultPriority));
716 719
717 // Create one asynchronous request. 720 // Create one asynchronous request.
718 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); 721 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob);
719 EXPECT_EQ(ERR_IO_PENDING, StartRequest("d", kDefaultPriority)); 722 EXPECT_EQ(ERR_IO_PENDING, StartRequest("d", kDefaultPriority));
723 PlatformThread::Sleep(10);
724 MessageLoop::current()->RunAllPending();
720 725
721 // The next synchronous request should wait for its turn. 726 // The next synchronous request should wait for its turn.
722 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); 727 connect_job_factory_->set_job_type(TestConnectJob::kMockJob);
723 EXPECT_EQ(ERR_IO_PENDING, StartRequest("e", kDefaultPriority)); 728 EXPECT_EQ(ERR_IO_PENDING, StartRequest("e", kDefaultPriority));
724 729
725 ReleaseAllConnections(KEEP_ALIVE); 730 ReleaseAllConnections(KEEP_ALIVE);
726 731
727 EXPECT_EQ(static_cast<int>(requests_.size()), 732 EXPECT_EQ(static_cast<int>(requests_.size()),
728 client_socket_factory_.allocation_count()); 733 client_socket_factory_.allocation_count());
729 734
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 next_job_type_(next_job_type) {} 951 next_job_type_(next_job_type) {}
947 952
948 virtual void RunWithParams(const Tuple1<int>& params) { 953 virtual void RunWithParams(const Tuple1<int>& params) {
949 callback_.RunWithParams(params); 954 callback_.RunWithParams(params);
950 ASSERT_EQ(OK, params.a); 955 ASSERT_EQ(OK, params.a);
951 956
952 if (!within_callback_) { 957 if (!within_callback_) {
953 test_connect_job_factory_->set_job_type(next_job_type_); 958 test_connect_job_factory_->set_job_type(next_job_type_);
954 handle_->Reset(); 959 handle_->Reset();
955 within_callback_ = true; 960 within_callback_ = true;
961 TestCompletionCallback next_job_callback;
956 int rv = InitHandle( 962 int rv = InitHandle(
957 handle_, "a", kDefaultPriority, this, pool_.get(), NULL); 963 handle_, "a", kDefaultPriority, &next_job_callback, pool_.get(),
964 NULL);
958 switch (next_job_type_) { 965 switch (next_job_type_) {
959 case TestConnectJob::kMockJob: 966 case TestConnectJob::kMockJob:
960 EXPECT_EQ(OK, rv); 967 EXPECT_EQ(OK, rv);
961 break; 968 break;
962 case TestConnectJob::kMockPendingJob: 969 case TestConnectJob::kMockPendingJob:
963 EXPECT_EQ(ERR_IO_PENDING, rv); 970 EXPECT_EQ(ERR_IO_PENDING, rv);
971
972 // For pending jobs, wait for new socket to be created. This makes
973 // sure there are no more pending operations nor any unclosed sockets
974 // when the test finishes.
975 // We need to give it a little bit of time to run, so that all the
976 // operations that happen on timers (e.g. cleanup of idle
977 // connections) can execute.
978 MessageLoop::current()->SetNestableTasksAllowed(true);
979 PlatformThread::Sleep(10);
980 EXPECT_EQ(OK, next_job_callback.WaitForResult());
964 break; 981 break;
965 default: 982 default:
966 FAIL() << "Unexpected job type: " << next_job_type_; 983 FAIL() << "Unexpected job type: " << next_job_type_;
967 break; 984 break;
968 } 985 }
969 } 986 }
970 } 987 }
971 988
972 int WaitForResult() { 989 int WaitForResult() {
973 return callback_.WaitForResult(); 990 return callback_.WaitForResult();
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 1841
1825 pool_->CleanupTimedOutIdleSockets(); 1842 pool_->CleanupTimedOutIdleSockets();
1826 rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), NULL); 1843 rv = InitHandle(req.handle(), "a", 0, &req, pool_.get(), NULL);
1827 EXPECT_EQ(OK, rv); 1844 EXPECT_EQ(OK, rv);
1828 EXPECT_TRUE(req.handle()->is_reused()); 1845 EXPECT_TRUE(req.handle()->is_reused());
1829 } 1846 }
1830 1847
1831 } // namespace 1848 } // namespace
1832 1849
1833 } // namespace net 1850 } // namespace net
OLDNEW
« no previous file with comments | « base/timer.cc ('k') | net/socket/socket_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698