OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/test/scoped_task_environment.h" | 5 #include "base/test/scoped_task_environment.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/task_scheduler/scheduler_worker_pool_params.h" | 8 #include "base/task_scheduler/scheduler_worker_pool_params.h" |
9 #include "base/task_scheduler/task_scheduler.h" | 9 #include "base/task_scheduler/task_scheduler.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 const SchedulerWorkerPoolParams worker_pool_params( | 48 const SchedulerWorkerPoolParams worker_pool_params( |
49 SchedulerWorkerPoolParams::StandbyThreadPolicy::ONE, kMaxThreads, | 49 SchedulerWorkerPoolParams::StandbyThreadPolicy::ONE, kMaxThreads, |
50 kSuggestedReclaimTime); | 50 kSuggestedReclaimTime); |
51 TaskScheduler::Create("ScopedTaskEnvironment"); | 51 TaskScheduler::Create("ScopedTaskEnvironment"); |
52 task_scheduler_ = TaskScheduler::GetInstance(); | 52 task_scheduler_ = TaskScheduler::GetInstance(); |
53 TaskScheduler::GetInstance()->Start({worker_pool_params, worker_pool_params, | 53 TaskScheduler::GetInstance()->Start({worker_pool_params, worker_pool_params, |
54 worker_pool_params, worker_pool_params}); | 54 worker_pool_params, worker_pool_params}); |
55 } | 55 } |
56 | 56 |
57 ScopedTaskEnvironment::~ScopedTaskEnvironment() { | 57 ScopedTaskEnvironment::~ScopedTaskEnvironment() { |
58 // Intentionally do not RunLoop().RunUntilIdle() here as this simulates the | 58 // Ideally this would RunLoop().RunUntilIdle() here to catch any errors or |
59 // replaced base::~MessageLoop() behaviour better. | 59 // infinite post loop in the remaining work but this isn't possible right now |
| 60 // because base::~MessageLoop() didn't use to do this and adding it here would |
| 61 // make the migration away from MessageLoop that much harder. |
| 62 |
60 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_); | 63 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_); |
61 // Without FlushForTesting(), DeleteSoon() and ReleaseSoon() tasks could be | 64 // Without FlushForTesting(), DeleteSoon() and ReleaseSoon() tasks could be |
62 // skipped, resulting in memory leaks. | 65 // skipped, resulting in memory leaks. |
63 TaskScheduler::GetInstance()->FlushForTesting(); | 66 TaskScheduler::GetInstance()->FlushForTesting(); |
64 TaskScheduler::GetInstance()->Shutdown(); | 67 TaskScheduler::GetInstance()->Shutdown(); |
65 TaskScheduler::GetInstance()->JoinForTesting(); | 68 TaskScheduler::GetInstance()->JoinForTesting(); |
66 TaskScheduler::SetInstance(nullptr); | 69 TaskScheduler::SetInstance(nullptr); |
67 } | 70 } |
68 | 71 |
69 scoped_refptr<base::SingleThreadTaskRunner> | 72 scoped_refptr<base::SingleThreadTaskRunner> |
(...skipping 10 matching lines...) Expand all Loading... |
80 RunLoop().RunUntilIdle(); | 83 RunLoop().RunUntilIdle(); |
81 MessageLoop::current()->RemoveTaskObserver(&task_observer); | 84 MessageLoop::current()->RemoveTaskObserver(&task_observer); |
82 | 85 |
83 if (!task_observer.ran_task()) | 86 if (!task_observer.ran_task()) |
84 return; | 87 return; |
85 } | 88 } |
86 } | 89 } |
87 | 90 |
88 } // namespace test | 91 } // namespace test |
89 } // namespace base | 92 } // namespace base |
OLD | NEW |