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

Side by Side Diff: base/threading/sequenced_worker_pool_unittest.cc

Issue 9401032: Make SequencedWorkerPool a TaskRunner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 8 years, 9 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/threading/sequenced_worker_pool.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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/synchronization/condition_variable.h" 9 #include "base/synchronization/condition_variable.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "base/task_runner_test_template.h"
11 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
12 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/tracked_objects.h" 14 #include "base/tracked_objects.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace base { 17 namespace base {
17 18
18 // IMPORTANT NOTE: 19 // IMPORTANT NOTE:
19 // 20 //
20 // Many of these tests have failure modes where they'll hang forever. These 21 // Many of these tests have failure modes where they'll hang forever. These
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 size_t expected_tasks_to_complete, 217 size_t expected_tasks_to_complete,
217 ThreadBlocker* blocker, 218 ThreadBlocker* blocker,
218 size_t threads_to_awake) { 219 size_t threads_to_awake) {
219 EXPECT_EQ( 220 EXPECT_EQ(
220 expected_tasks_to_complete, 221 expected_tasks_to_complete,
221 tracker->WaitUntilTasksComplete(expected_tasks_to_complete).size()); 222 tracker->WaitUntilTasksComplete(expected_tasks_to_complete).size());
222 223
223 blocker->Unblock(threads_to_awake); 224 blocker->Unblock(threads_to_awake);
224 } 225 }
225 226
226 } // namespace
227
228 // Tests that same-named tokens have the same ID. 227 // Tests that same-named tokens have the same ID.
229 TEST_F(SequencedWorkerPoolTest, NamedTokens) { 228 TEST_F(SequencedWorkerPoolTest, NamedTokens) {
230 const std::string name1("hello"); 229 const std::string name1("hello");
231 SequencedWorkerPool::SequenceToken token1 = 230 SequencedWorkerPool::SequenceToken token1 =
232 pool()->GetNamedSequenceToken(name1); 231 pool()->GetNamedSequenceToken(name1);
233 232
234 SequencedWorkerPool::SequenceToken token2 = pool()->GetSequenceToken(); 233 SequencedWorkerPool::SequenceToken token2 = pool()->GetSequenceToken();
235 234
236 const std::string name3("goodbye"); 235 const std::string name3("goodbye");
237 SequencedWorkerPool::SequenceToken token3 = 236 SequencedWorkerPool::SequenceToken token3 =
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( 395 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior(
397 FROM_HERE, base::Bind(&TestTracker::FastTask, tracker(), 0), 396 FROM_HERE, base::Bind(&TestTracker::FastTask, tracker(), 0),
398 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); 397 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN));
399 398
400 // Continue the background thread and make sure the task can complete. 399 // Continue the background thread and make sure the task can complete.
401 blocker.Unblock(1); 400 blocker.Unblock(1);
402 std::vector<int> result = tracker()->WaitUntilTasksComplete(1); 401 std::vector<int> result = tracker()->WaitUntilTasksComplete(1);
403 EXPECT_EQ(1u, result.size()); 402 EXPECT_EQ(1u, result.size());
404 } 403 }
405 404
405 class SequencedWorkerPoolTaskRunnerTestDelegate {
406 public:
407 SequencedWorkerPoolTaskRunnerTestDelegate() {}
408
409 ~SequencedWorkerPoolTaskRunnerTestDelegate() {}
410
411 void StartTaskRunner() {
412 worker_pool_ =
413 new SequencedWorkerPool(10, "SequencedWorkerPoolTaskRunnerTest");
414 }
415
416 scoped_refptr<SequencedWorkerPool> GetTaskRunner() {
417 return worker_pool_;
418 }
419
420 void StopTaskRunner() {
421 worker_pool_->Shutdown();
422 worker_pool_ = NULL;
423 }
424
425 bool TaskRunnerHandlesNonZeroDelays() const {
426 // TODO(akalin): Set this to true once SequencedWorkerPool handles
427 // non-zero delays.
428 return false;
429 }
430
431 private:
432 scoped_refptr<SequencedWorkerPool> worker_pool_;
433 };
434
435 INSTANTIATE_TYPED_TEST_CASE_P(
436 SequencedWorkerPool, TaskRunnerTest,
437 SequencedWorkerPoolTaskRunnerTestDelegate);
438
439 } // namespace
440
406 } // namespace base 441 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698