| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/task_scheduler/task_tracker.h" | 5 #include "base/task_scheduler/task_tracker.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 class TaskSchedulerTaskTrackerTest | 64 class TaskSchedulerTaskTrackerTest |
| 65 : public testing::TestWithParam<TaskShutdownBehavior> { | 65 : public testing::TestWithParam<TaskShutdownBehavior> { |
| 66 protected: | 66 protected: |
| 67 TaskSchedulerTaskTrackerTest() = default; | 67 TaskSchedulerTaskTrackerTest() = default; |
| 68 | 68 |
| 69 // Creates a task with |shutdown_behavior|. | 69 // Creates a task with |shutdown_behavior|. |
| 70 std::unique_ptr<Task> CreateTask(TaskShutdownBehavior shutdown_behavior) { | 70 std::unique_ptr<Task> CreateTask(TaskShutdownBehavior shutdown_behavior) { |
| 71 return WrapUnique(new Task( | 71 return WrapUnique(new Task( |
| 72 FROM_HERE, | 72 FROM_HERE, |
| 73 Bind(&TaskSchedulerTaskTrackerTest::RunTaskCallback, Unretained(this)), | 73 Bind(&TaskSchedulerTaskTrackerTest::RunTaskCallback, Unretained(this)), |
| 74 TaskTraits().WithShutdownBehavior(shutdown_behavior))); | 74 TaskTraits().WithShutdownBehavior(shutdown_behavior), TimeTicks())); |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Calls tracker_->Shutdown() on a new thread. When this returns, Shutdown() | 77 // Calls tracker_->Shutdown() on a new thread. When this returns, Shutdown() |
| 78 // method has been entered on the new thread, but it hasn't necessarily | 78 // method has been entered on the new thread, but it hasn't necessarily |
| 79 // returned. | 79 // returned. |
| 80 void CallShutdownAsync() { | 80 void CallShutdownAsync() { |
| 81 ASSERT_FALSE(thread_calling_shutdown_); | 81 ASSERT_FALSE(thread_calling_shutdown_); |
| 82 thread_calling_shutdown_.reset(new ThreadCallingShutdown(&tracker_)); | 82 thread_calling_shutdown_.reset(new ThreadCallingShutdown(&tracker_)); |
| 83 thread_calling_shutdown_->Start(); | 83 thread_calling_shutdown_->Start(); |
| 84 while (!tracker_.IsShuttingDownForTesting() && | 84 while (!tracker_.IsShuttingDownForTesting() && |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 // Shutdown() shouldn't block. | 140 // Shutdown() shouldn't block. |
| 141 tracker_.Shutdown(); | 141 tracker_.Shutdown(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 TEST_P(TaskSchedulerTaskTrackerTest, WillPostAndRunLongTaskBeforeShutdown) { | 144 TEST_P(TaskSchedulerTaskTrackerTest, WillPostAndRunLongTaskBeforeShutdown) { |
| 145 // Create a task that will block until |event| is signaled. | 145 // Create a task that will block until |event| is signaled. |
| 146 WaitableEvent event(false, false); | 146 WaitableEvent event(false, false); |
| 147 std::unique_ptr<Task> blocked_task( | 147 std::unique_ptr<Task> blocked_task( |
| 148 new Task(FROM_HERE, Bind(&WaitableEvent::Wait, Unretained(&event)), | 148 new Task(FROM_HERE, Bind(&WaitableEvent::Wait, Unretained(&event)), |
| 149 TaskTraits().WithShutdownBehavior(GetParam()))); | 149 TaskTraits().WithShutdownBehavior(GetParam()), TimeTicks())); |
| 150 | 150 |
| 151 // Inform |task_tracker_| that |blocked_task| will be posted. | 151 // Inform |task_tracker_| that |blocked_task| will be posted. |
| 152 EXPECT_TRUE(tracker_.WillPostTask(blocked_task.get())); | 152 EXPECT_TRUE(tracker_.WillPostTask(blocked_task.get())); |
| 153 | 153 |
| 154 // Run the task asynchronouly. | 154 // Run the task asynchronouly. |
| 155 ThreadRunningTask thread_running_task(&tracker_, blocked_task.get()); | 155 ThreadRunningTask thread_running_task(&tracker_, blocked_task.get()); |
| 156 thread_running_task.Start(); | 156 thread_running_task.Start(); |
| 157 | 157 |
| 158 // Initiate shutdown while the task is running. | 158 // Initiate shutdown while the task is running. |
| 159 CallShutdownAsync(); | 159 CallShutdownAsync(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 SkipOnShutdown, | 291 SkipOnShutdown, |
| 292 TaskSchedulerTaskTrackerTest, | 292 TaskSchedulerTaskTrackerTest, |
| 293 ::testing::Values(TaskShutdownBehavior::SKIP_ON_SHUTDOWN)); | 293 ::testing::Values(TaskShutdownBehavior::SKIP_ON_SHUTDOWN)); |
| 294 INSTANTIATE_TEST_CASE_P( | 294 INSTANTIATE_TEST_CASE_P( |
| 295 BlockShutdown, | 295 BlockShutdown, |
| 296 TaskSchedulerTaskTrackerTest, | 296 TaskSchedulerTaskTrackerTest, |
| 297 ::testing::Values(TaskShutdownBehavior::BLOCK_SHUTDOWN)); | 297 ::testing::Values(TaskShutdownBehavior::BLOCK_SHUTDOWN)); |
| 298 | 298 |
| 299 } // namespace internal | 299 } // namespace internal |
| 300 } // namespace base | 300 } // namespace base |
| OLD | NEW |