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

Unified Diff: base/threading/sequenced_worker_pool_unittest.cc

Issue 9689028: Move work signal count tracking from SequencedWorkerPool to the test file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/threading/sequenced_worker_pool.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/sequenced_worker_pool_unittest.cc
diff --git a/base/threading/sequenced_worker_pool_unittest.cc b/base/threading/sequenced_worker_pool_unittest.cc
index 7649a6d38f9c6756ae704b49f84e45f8ae7294a6..e44599f246340c51f67931a5933ba35d08dfc5df 100644
--- a/base/threading/sequenced_worker_pool_unittest.cc
+++ b/base/threading/sequenced_worker_pool_unittest.cc
@@ -157,9 +157,10 @@ class SequencedWorkerPoolOwner : public SequencedWorkerPool::TestingObserver {
SequencedWorkerPoolOwner(size_t max_threads,
const std::string& thread_name_prefix)
: constructor_message_loop_(MessageLoop::current()),
- pool_(new SequencedWorkerPool(max_threads, thread_name_prefix)) {
- pool_->SetTestingObserver(this);
- }
+ pool_(new SequencedWorkerPool(
+ max_threads, thread_name_prefix,
+ ALLOW_THIS_IN_INITIALIZER_LIST(this))),
+ has_work_call_count_(0) {}
virtual ~SequencedWorkerPoolOwner() {
pool_ = NULL;
@@ -176,8 +177,18 @@ class SequencedWorkerPoolOwner : public SequencedWorkerPool::TestingObserver {
will_wait_for_shutdown_callback_ = callback;
}
+ int has_work_call_count() const {
+ AutoLock lock(has_work_lock_);
+ return has_work_call_count_;
+ }
+
private:
// SequencedWorkerPool::TestingObserver implementation.
+ virtual void OnHasWork() OVERRIDE {
+ AutoLock lock(has_work_lock_);
+ ++has_work_call_count_;
+ }
+
virtual void WillWaitForShutdown() OVERRIDE {
if (!will_wait_for_shutdown_callback_.is_null()) {
will_wait_for_shutdown_callback_.Run();
@@ -194,6 +205,9 @@ class SequencedWorkerPoolOwner : public SequencedWorkerPool::TestingObserver {
scoped_refptr<SequencedWorkerPool> pool_;
Closure will_wait_for_shutdown_callback_;
+ mutable Lock has_work_lock_;
+ int has_work_call_count_;
+
DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolOwner);
};
@@ -253,6 +267,10 @@ class SequencedWorkerPoolTest : public testing::Test {
tracker()->ClearCompleteSequence();
}
+ int has_work_call_count() const {
+ return pool_owner_.has_work_call_count();
+ }
+
private:
MessageLoop message_loop_;
SequencedWorkerPoolOwner pool_owner_;
@@ -485,11 +503,11 @@ TEST_F(SequencedWorkerPoolTest, ContinueOnShutdown) {
// triggered. This is a regression test for http://crbug.com/117469.
TEST_F(SequencedWorkerPoolTest, SpuriousWorkSignal) {
EnsureAllWorkersCreated();
- int old_work_signal_count = pool()->GetWorkSignalCountForTesting();
- pool()->TriggerSpuriousWorkSignalForTesting();
+ int old_has_work_call_count = has_work_call_count();
+ pool()->SignalHasWorkForTesting();
// This is inherently racy, but can only produce false positives.
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
- EXPECT_EQ(old_work_signal_count + 1, pool()->GetWorkSignalCountForTesting());
+ EXPECT_EQ(old_has_work_call_count + 1, has_work_call_count());
}
class SequencedWorkerPoolTaskRunnerTestDelegate {
« 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