Index: base/task_scheduler/scheduler_worker_pool_impl_unittest.cc |
diff --git a/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc b/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc |
index 1858ac5cdbd972cd80e88adb6bf1de8631c4c3e4..fb25da745acc9ddfcdf5bf7ab3f7084d97fd1768 100644 |
--- a/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc |
+++ b/base/task_scheduler/scheduler_worker_pool_impl_unittest.cc |
@@ -364,6 +364,42 @@ TEST_P(TaskSchedulerWorkerPoolImplTest, SequencedRunsTasksOnCurrentThread) { |
task_ran.Wait(); |
} |
+// Verify that the RunsTasksOnCurrentThread() method of a SINGLE_THREADED |
fdoray
2016/11/04 15:20:43
s/SINGLE_THREADED TaskRunner/SingleThreadTaskRunne
gab
2016/11/04 17:56:13
Okay but I used SchedulerSingleThreadTaskRunner as
|
+// TaskRunner returns false when called from a task that isn't part of its |
+// sequence. Even when there are enough TaskRunners of the tested types for some |
+// tasks to be assigned to the same worker. |
robliao
2016/11/03 22:59:56
If we stop round robining the workers for single t
gab
2016/11/03 23:17:44
It would still work. Note that this test is parame
robliao
2016/11/03 23:29:32
Ah, in that case would it be sufficient to simply
gab
2016/11/03 23:39:50
This could deadlock in the SINGLE_THREADED case (e
robliao
2016/11/04 00:56:47
I think I would prefer a deadlocked test if/when w
gab
2016/11/04 14:47:59
I disagree, the worker assignment policy is orthog
fdoray
2016/11/04 15:20:43
After reading the "Resilience" section from https:
robliao
2016/11/04 16:59:36
I think I would be okay with this. That's a good c
gab
2016/11/04 17:56:13
I like this too, done.
|
+TEST_P(TaskSchedulerWorkerPoolImplTest, SingleThreadRunsTasksOnCurrentThread) { |
+ constexpr size_t kNumFloodingTaskRunners = 50; |
robliao
2016/11/03 22:59:56
Nit: Move this constexpr to the group near the top
gab
2016/11/03 23:17:44
No, it's specific to this test so it's preferred t
|
+ std::vector<scoped_refptr<TaskRunner>> task_runners; |
+ std::vector<std::unique_ptr<WaitableEvent>> task_signals; |
+ for (size_t i = 0; i < kNumFloodingTaskRunners; ++i) { |
+ task_runners.push_back( |
+ CreateTaskRunnerWithExecutionMode(worker_pool_.get(), GetParam())); |
+ task_signals.emplace_back( |
+ new WaitableEvent(WaitableEvent::ResetPolicy::MANUAL, |
+ WaitableEvent::InitialState::NOT_SIGNALED)); |
+ } |
+ |
+ scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner( |
+ worker_pool_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits())); |
+ |
+ for (size_t i = 0; i < kNumFloodingTaskRunners; ++i) { |
+ task_runners[i]->PostTask( |
+ FROM_HERE, |
+ Bind( |
+ [](scoped_refptr<TaskRunner> single_thread_task_runner, |
+ WaitableEvent* task_signal) { |
+ EXPECT_FALSE( |
+ single_thread_task_runner->RunsTasksOnCurrentThread()); |
+ task_signal->Signal(); |
+ }, |
+ single_thread_task_runner, Unretained(task_signals[i].get()))); |
+ } |
+ |
+ for (auto& task_signal : task_signals) |
+ task_signal->Wait(); |
+} |
+ |
INSTANTIATE_TEST_CASE_P(Parallel, |
TaskSchedulerWorkerPoolImplTest, |
::testing::Values(test::ExecutionMode::PARALLEL)); |