OLD | NEW |
---|---|
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 Loading... | |
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 | |
Sigurður Ásgeirsson
2012/03/12 13:01:40
nit: one space after full stop, same below.
akalin
2012/03/12 18:34:34
Done.
| |
485 // triggered. This is a regression test for http://crbug.com/117469. | |
486 TEST_F(SequencedWorkerPoolTest, SpuriousWorkSignal) { | |
Sigurður Ásgeirsson
2012/03/12 13:01:40
Nice!
| |
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 Loading... | |
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 |
OLD | NEW |