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

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

Issue 2994003: Refactor how ClientSocketPoolBaseHelper avoids re-entrancy. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Merge. Created 10 years, 5 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/socket/client_socket_pool_base.cc ('k') | net/socket/socket_test_util.h » ('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) 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 CompletionCallback* callback, 363 CompletionCallback* callback,
364 const BoundNetLog& net_log) { 364 const BoundNetLog& net_log) {
365 const scoped_refptr<TestSocketParams>* casted_socket_params = 365 const scoped_refptr<TestSocketParams>* casted_socket_params =
366 static_cast<const scoped_refptr<TestSocketParams>*>(params); 366 static_cast<const scoped_refptr<TestSocketParams>*>(params);
367 return base_.RequestSocket(group_name, *casted_socket_params, priority, 367 return base_.RequestSocket(group_name, *casted_socket_params, priority,
368 handle, callback, net_log); 368 handle, callback, net_log);
369 } 369 }
370 370
371 virtual void CancelRequest( 371 virtual void CancelRequest(
372 const std::string& group_name, 372 const std::string& group_name,
373 const ClientSocketHandle* handle) { 373 ClientSocketHandle* handle) {
374 base_.CancelRequest(group_name, handle); 374 base_.CancelRequest(group_name, handle);
375 } 375 }
376 376
377 virtual void ReleaseSocket( 377 virtual void ReleaseSocket(
378 const std::string& group_name, 378 const std::string& group_name,
379 ClientSocket* socket, 379 ClientSocket* socket,
380 int id) { 380 int id) {
381 base_.ReleaseSocket(group_name, socket, id); 381 base_.ReleaseSocket(group_name, socket, id);
382 } 382 }
383 383
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // actually become pending until 2ms after they have been created. In order 514 // actually become pending until 2ms after they have been created. In order
515 // to flush all tasks, we need to wait so that we know there are no 515 // to flush all tasks, we need to wait so that we know there are no
516 // soon-to-be-pending tasks waiting. 516 // soon-to-be-pending tasks waiting.
517 PlatformThread::Sleep(10); 517 PlatformThread::Sleep(10);
518 MessageLoop::current()->RunAllPending(); 518 MessageLoop::current()->RunAllPending();
519 519
520 // Need to delete |pool_| before we turn late binding back off. We also need 520 // Need to delete |pool_| before we turn late binding back off. We also need
521 // to delete |requests_| because the pool is reference counted and requests 521 // to delete |requests_| because the pool is reference counted and requests
522 // keep reference to it. 522 // keep reference to it.
523 // TODO(willchan): Remove this part when late binding becomes the default. 523 // TODO(willchan): Remove this part when late binding becomes the default.
524 TestClientSocketPool* pool = pool_.get();
524 pool_ = NULL; 525 pool_ = NULL;
525 requests_.reset(); 526 requests_.reset();
527 pool = NULL;
526 528
527 ClientSocketPoolTest::TearDown(); 529 ClientSocketPoolTest::TearDown();
528 } 530 }
529 531
530 MockClientSocketFactory client_socket_factory_; 532 MockClientSocketFactory client_socket_factory_;
531 TestConnectJobFactory* connect_job_factory_; 533 TestConnectJobFactory* connect_job_factory_;
532 scoped_refptr<TestSocketParams> params_; 534 scoped_refptr<TestSocketParams> params_;
533 scoped_refptr<TestClientSocketPool> pool_; 535 scoped_refptr<TestClientSocketPool> pool_;
534 scoped_refptr<ClientSocketPoolHistograms> histograms_; 536 scoped_refptr<ClientSocketPoolHistograms> histograms_;
535 }; 537 };
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", params_, 929 EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", params_,
928 kDefaultPriority, &callback, 930 kDefaultPriority, &callback,
929 pool_, BoundNetLog())); 931 pool_, BoundNetLog()));
930 932
931 // Since it is stalled, it should have no connect jobs. 933 // Since it is stalled, it should have no connect jobs.
932 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("foo")); 934 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("foo"));
933 935
934 // Cancel the stalled request. 936 // Cancel the stalled request.
935 handles[0].Reset(); 937 handles[0].Reset();
936 938
937 // Wait for the pending job to be guaranteed to complete.
938 PlatformThread::Sleep(TestConnectJob::kPendingConnectDelay * 2);
939
940 MessageLoop::current()->RunAllPending();
941
942 // Now we should have a connect job. 939 // Now we should have a connect job.
943 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("foo")); 940 EXPECT_EQ(1, pool_->NumConnectJobsInGroup("foo"));
944 941
945 // The stalled socket should connect. 942 // The stalled socket should connect.
946 EXPECT_EQ(OK, callback.WaitForResult()); 943 EXPECT_EQ(OK, callback.WaitForResult());
947 944
948 EXPECT_EQ(kDefaultMaxSockets + 1, 945 EXPECT_EQ(kDefaultMaxSockets + 1,
949 client_socket_factory_.allocation_count()); 946 client_socket_factory_.allocation_count());
950 EXPECT_EQ(0, pool_->IdleSocketCount()); 947 EXPECT_EQ(0, pool_->IdleSocketCount());
951 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("foo")); 948 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("foo"));
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 // Finally, signal the waiting Connect. 2090 // Finally, signal the waiting Connect.
2094 client_socket_factory_.SignalJobs(); 2091 client_socket_factory_.SignalJobs();
2095 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a")); 2092 EXPECT_EQ(0, pool_->NumConnectJobsInGroup("a"));
2096 2093
2097 MessageLoop::current()->RunAllPending(); 2094 MessageLoop::current()->RunAllPending();
2098 } 2095 }
2099 2096
2100 } // namespace 2097 } // namespace
2101 2098
2102 } // namespace net 2099 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base.cc ('k') | net/socket/socket_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698