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 "base/threading/sequenced_worker_pool.h" |
| 6 |
5 #include <algorithm> | 7 #include <algorithm> |
6 | 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
12 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
13 #include "base/synchronization/condition_variable.h" | 15 #include "base/synchronization/condition_variable.h" |
14 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
15 #include "base/test/sequenced_worker_pool_owner.h" | 17 #include "base/test/sequenced_worker_pool_owner.h" |
| 18 #include "base/test/sequenced_task_runner_test_template.h" |
16 #include "base/test/task_runner_test_template.h" | 19 #include "base/test/task_runner_test_template.h" |
17 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
18 #include "base/threading/sequenced_worker_pool.h" | |
19 #include "base/tracked_objects.h" | 21 #include "base/tracked_objects.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 | 23 |
22 namespace base { | 24 namespace base { |
23 | 25 |
24 // IMPORTANT NOTE: | 26 // IMPORTANT NOTE: |
25 // | 27 // |
26 // Many of these tests have failure modes where they'll hang forever. These | 28 // Many of these tests have failure modes where they'll hang forever. These |
27 // tests should not be flaky, and hangling indicates a type of failure. Do not | 29 // tests should not be flaky, and hangling indicates a type of failure. Do not |
28 // mark as flaky if they're hanging, it's likely an actual bug. | 30 // mark as flaky if they're hanging, it's likely an actual bug. |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 528 |
527 private: | 529 private: |
528 MessageLoop message_loop_; | 530 MessageLoop message_loop_; |
529 scoped_ptr<SequencedWorkerPoolOwner> pool_owner_; | 531 scoped_ptr<SequencedWorkerPoolOwner> pool_owner_; |
530 }; | 532 }; |
531 | 533 |
532 INSTANTIATE_TYPED_TEST_CASE_P( | 534 INSTANTIATE_TYPED_TEST_CASE_P( |
533 SequencedWorkerPool, TaskRunnerTest, | 535 SequencedWorkerPool, TaskRunnerTest, |
534 SequencedWorkerPoolTaskRunnerTestDelegate); | 536 SequencedWorkerPoolTaskRunnerTestDelegate); |
535 | 537 |
| 538 class SequencedWorkerPoolSequencedTaskRunnerTestDelegate { |
| 539 public: |
| 540 SequencedWorkerPoolSequencedTaskRunnerTestDelegate() {} |
| 541 |
| 542 ~SequencedWorkerPoolSequencedTaskRunnerTestDelegate() { |
| 543 } |
| 544 |
| 545 void StartTaskRunner() { |
| 546 pool_owner_.reset(new SequencedWorkerPoolOwner( |
| 547 10, "SequencedWorkerPoolSequencedTaskRunnerTest")); |
| 548 task_runner_ = pool_owner_->pool()->GetSequencedTaskRunner( |
| 549 pool_owner_->pool()->GetSequenceToken()); |
| 550 } |
| 551 |
| 552 scoped_refptr<SequencedTaskRunner> GetTaskRunner() { |
| 553 return task_runner_; |
| 554 } |
| 555 |
| 556 void StopTaskRunner() { |
| 557 pool_owner_->pool()->FlushForTesting(); |
| 558 pool_owner_->pool()->Shutdown(); |
| 559 // Don't reset |pool_owner_| here, as the test may still hold a |
| 560 // reference to the pool. |
| 561 } |
| 562 |
| 563 bool TaskRunnerHandlesNonZeroDelays() const { |
| 564 // TODO(akalin): Set this to true once SequencedWorkerPool handles |
| 565 // non-zero delays. |
| 566 return false; |
| 567 } |
| 568 |
| 569 private: |
| 570 MessageLoop message_loop_; |
| 571 scoped_ptr<SequencedWorkerPoolOwner> pool_owner_; |
| 572 scoped_refptr<SequencedTaskRunner> task_runner_; |
| 573 }; |
| 574 |
| 575 INSTANTIATE_TYPED_TEST_CASE_P( |
| 576 SequencedWorkerPoolSequencedTaskRunner, TaskRunnerTest, |
| 577 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); |
| 578 |
| 579 INSTANTIATE_TYPED_TEST_CASE_P( |
| 580 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, |
| 581 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); |
| 582 |
536 } // namespace | 583 } // namespace |
537 | 584 |
538 } // namespace base | 585 } // namespace base |
OLD | NEW |