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

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

Issue 12647013: Regularize storage monitor creation in Windows. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 8 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
« no previous file with comments | « base/threading/sequenced_worker_pool.h ('k') | chrome/browser/chrome_browser_main_win.h » ('j') | 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 "base/threading/sequenced_worker_pool.h" 5 #include "base/threading/sequenced_worker_pool.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 10 matching lines...) Expand all
21 #include "base/threading/platform_thread.h" 21 #include "base/threading/platform_thread.h"
22 #include "base/time.h" 22 #include "base/time.h"
23 #include "base/tracked_objects.h" 23 #include "base/tracked_objects.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 namespace base { 26 namespace base {
27 27
28 // IMPORTANT NOTE: 28 // IMPORTANT NOTE:
29 // 29 //
30 // Many of these tests have failure modes where they'll hang forever. These 30 // Many of these tests have failure modes where they'll hang forever. These
31 // tests should not be flaky, and hangling indicates a type of failure. Do not 31 // tests should not be flaky, and hanging indicates a type of failure. Do not
32 // mark as flaky if they're hanging, it's likely an actual bug. 32 // mark as flaky if they're hanging, it's likely an actual bug.
33 33
34 namespace { 34 namespace {
35 35
36 const size_t kNumWorkerThreads = 3; 36 const size_t kNumWorkerThreads = 3;
37 37
38 // Allows a number of threads to all be blocked on the same event, and 38 // Allows a number of threads to all be blocked on the same event, and
39 // provides a way to unblock a certain number of them. 39 // provides a way to unblock a certain number of them.
40 class ThreadBlocker { 40 class ThreadBlocker {
41 public: 41 public:
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 for (size_t i = 0; i < kNumFastTasks; i++) { 774 for (size_t i = 0; i < kNumFastTasks; i++) {
775 pool()->PostWorkerTask(FROM_HERE, 775 pool()->PostWorkerTask(FROM_HERE,
776 base::Bind(&TestTracker::FastTask, tracker(), 0)); 776 base::Bind(&TestTracker::FastTask, tracker(), 0));
777 } 777 }
778 pool()->PostWorkerTask( 778 pool()->PostWorkerTask(
779 FROM_HERE, 779 FROM_HERE,
780 base::Bind(&TestTracker::PostAdditionalTasks, tracker(), 0, pool(), 780 base::Bind(&TestTracker::PostAdditionalTasks, tracker(), 0, pool(),
781 true)); 781 true));
782 782
783 // We expect all except the delayed task to have been run. We verify all 783 // We expect all except the delayed task to have been run. We verify all
784 // closures have been deleted deleted by looking at the refcount of the 784 // closures have been deleted deleted by looking at the refcount of the
jar (doing other things) 2013/04/18 01:56:23 nit: "deleted deleted" since you're cleaning up
Greg Billock 2013/04/18 02:02:04 Done.
785 // tracker. 785 // tracker.
786 EXPECT_FALSE(tracker()->HasOneRef()); 786 EXPECT_FALSE(tracker()->HasOneRef());
787 pool()->FlushForTesting(); 787 pool()->FlushForTesting();
788 EXPECT_TRUE(tracker()->HasOneRef()); 788 EXPECT_TRUE(tracker()->HasOneRef());
789 EXPECT_EQ(1 + kNumFastTasks + 1 + 3, tracker()->GetTasksCompletedCount()); 789 EXPECT_EQ(1 + kNumFastTasks + 1 + 3, tracker()->GetTasksCompletedCount());
790 790
791 // Should be fine to call on an idle instance with all threads created, and 791 // Should be fine to call on an idle instance with all threads created, and
792 // spamming the method shouldn't deadlock or confuse the class. 792 // spamming the method shouldn't deadlock or confuse the class.
793 pool()->FlushForTesting(); 793 pool()->FlushForTesting();
794 pool()->FlushForTesting(); 794 pool()->FlushForTesting();
795 795
796 // Should be fine to call after shutdown too. 796 // Should be fine to call after shutdown too.
797 pool()->Shutdown(); 797 pool()->Shutdown();
798 pool()->FlushForTesting(); 798 pool()->FlushForTesting();
799 } 799 }
800 800
801 TEST(SequencedWorkerPoolRefPtrTest, ShutsDownCleanWithContinueOnShutdown) {
802 MessageLoop loop;
803 scoped_refptr<SequencedWorkerPool> pool(new SequencedWorkerPool(3, "Pool"));
804 scoped_refptr<SequencedTaskRunner> task_runner =
805 pool->GetSequencedTaskRunnerWithShutdownBehavior(
806 pool->GetSequenceToken(),
807 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
808
809 // Upon test exit, should shut down without hanging.
810 pool->Shutdown();
811 }
812
801 class SequencedWorkerPoolTaskRunnerTestDelegate { 813 class SequencedWorkerPoolTaskRunnerTestDelegate {
802 public: 814 public:
803 SequencedWorkerPoolTaskRunnerTestDelegate() {} 815 SequencedWorkerPoolTaskRunnerTestDelegate() {}
804 816
805 ~SequencedWorkerPoolTaskRunnerTestDelegate() {} 817 ~SequencedWorkerPoolTaskRunnerTestDelegate() {}
806 818
807 void StartTaskRunner() { 819 void StartTaskRunner() {
808 pool_owner_.reset( 820 pool_owner_.reset(
809 new SequencedWorkerPoolOwner(10, "SequencedWorkerPoolTaskRunnerTest")); 821 new SequencedWorkerPoolOwner(10, "SequencedWorkerPoolTaskRunnerTest"));
810 } 822 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 SequencedWorkerPoolSequencedTaskRunner, TaskRunnerTest, 929 SequencedWorkerPoolSequencedTaskRunner, TaskRunnerTest,
918 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 930 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
919 931
920 INSTANTIATE_TYPED_TEST_CASE_P( 932 INSTANTIATE_TYPED_TEST_CASE_P(
921 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest, 933 SequencedWorkerPoolSequencedTaskRunner, SequencedTaskRunnerTest,
922 SequencedWorkerPoolSequencedTaskRunnerTestDelegate); 934 SequencedWorkerPoolSequencedTaskRunnerTestDelegate);
923 935
924 } // namespace 936 } // namespace
925 937
926 } // namespace base 938 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool.h ('k') | chrome/browser/chrome_browser_main_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698