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

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

Issue 9651026: Clean up condition variable usage in SequencedWorkerPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits 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/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior( 473 EXPECT_FALSE(pool()->PostWorkerTaskWithShutdownBehavior(
474 FROM_HERE, base::Bind(&TestTracker::FastTask, tracker(), 0), 474 FROM_HERE, base::Bind(&TestTracker::FastTask, tracker(), 0),
475 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN)); 475 SequencedWorkerPool::CONTINUE_ON_SHUTDOWN));
476 476
477 // Continue the background thread and make sure the task can complete. 477 // Continue the background thread and make sure the task can complete.
478 blocker.Unblock(1); 478 blocker.Unblock(1);
479 std::vector<int> result = tracker()->WaitUntilTasksComplete(1); 479 std::vector<int> result = tracker()->WaitUntilTasksComplete(1);
480 EXPECT_EQ(1u, result.size()); 480 EXPECT_EQ(1u, result.size());
481 } 481 }
482 482
483 // Ensure all worker threads are created, and then trigger a spurious
484 // work signal. This shouldn't cause any other work signals to be
485 // triggered. This is a regression test for http://crbug.com/117469.
486 TEST_F(SequencedWorkerPoolTest, SpuriousWorkSignal) {
487 EnsureAllWorkersCreated();
488 int old_work_signal_count = pool()->GetWorkSignalCountForTesting();
489 pool()->TriggerSpuriousWorkSignalForTesting();
490 // This is inherently racy, but can only produce false positives.
491 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
492 EXPECT_EQ(old_work_signal_count + 1, pool()->GetWorkSignalCountForTesting());
493 }
494
483 class SequencedWorkerPoolTaskRunnerTestDelegate { 495 class SequencedWorkerPoolTaskRunnerTestDelegate {
484 public: 496 public:
485 SequencedWorkerPoolTaskRunnerTestDelegate() {} 497 SequencedWorkerPoolTaskRunnerTestDelegate() {}
486 498
487 ~SequencedWorkerPoolTaskRunnerTestDelegate() {} 499 ~SequencedWorkerPoolTaskRunnerTestDelegate() {}
488 500
489 void StartTaskRunner() { 501 void StartTaskRunner() {
490 pool_owner_.reset( 502 pool_owner_.reset(
491 new SequencedWorkerPoolOwner(10, "SequencedWorkerPoolTaskRunnerTest")); 503 new SequencedWorkerPoolOwner(10, "SequencedWorkerPoolTaskRunnerTest"));
492 } 504 }
(...skipping 19 matching lines...) Expand all
512 scoped_ptr<SequencedWorkerPoolOwner> pool_owner_; 524 scoped_ptr<SequencedWorkerPoolOwner> pool_owner_;
513 }; 525 };
514 526
515 INSTANTIATE_TYPED_TEST_CASE_P( 527 INSTANTIATE_TYPED_TEST_CASE_P(
516 SequencedWorkerPool, TaskRunnerTest, 528 SequencedWorkerPool, TaskRunnerTest,
517 SequencedWorkerPoolTaskRunnerTestDelegate); 529 SequencedWorkerPoolTaskRunnerTestDelegate);
518 530
519 } // namespace 531 } // namespace
520 532
521 } // namespace base 533 } // 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