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/scheduler_worker_pool_impl.h" | 5 #include "base/task_scheduler/scheduler_worker_pool_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <unordered_set> | 10 #include <unordered_set> |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
357 WaitableEvent* task_ran) { | 357 WaitableEvent* task_ran) { |
358 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); | 358 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); |
359 // Tests that use TestTaskFactory already verify that | 359 // Tests that use TestTaskFactory already verify that |
360 // RunsTasksOnCurrentThread() returns true when appropriate. | 360 // RunsTasksOnCurrentThread() returns true when appropriate. |
361 task_ran->Signal(); | 361 task_ran->Signal(); |
362 }, | 362 }, |
363 sequenced_task_runner, Unretained(&task_ran))); | 363 sequenced_task_runner, Unretained(&task_ran))); |
364 task_ran.Wait(); | 364 task_ran.Wait(); |
365 } | 365 } |
366 | 366 |
367 // 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
| |
368 // TaskRunner returns false when called from a task that isn't part of its | |
369 // sequence. Even when there are enough TaskRunners of the tested types for some | |
370 // 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.
| |
371 TEST_P(TaskSchedulerWorkerPoolImplTest, SingleThreadRunsTasksOnCurrentThread) { | |
372 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
| |
373 std::vector<scoped_refptr<TaskRunner>> task_runners; | |
374 std::vector<std::unique_ptr<WaitableEvent>> task_signals; | |
375 for (size_t i = 0; i < kNumFloodingTaskRunners; ++i) { | |
376 task_runners.push_back( | |
377 CreateTaskRunnerWithExecutionMode(worker_pool_.get(), GetParam())); | |
378 task_signals.emplace_back( | |
379 new WaitableEvent(WaitableEvent::ResetPolicy::MANUAL, | |
380 WaitableEvent::InitialState::NOT_SIGNALED)); | |
381 } | |
382 | |
383 scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner( | |
384 worker_pool_->CreateSingleThreadTaskRunnerWithTraits(TaskTraits())); | |
385 | |
386 for (size_t i = 0; i < kNumFloodingTaskRunners; ++i) { | |
387 task_runners[i]->PostTask( | |
388 FROM_HERE, | |
389 Bind( | |
390 [](scoped_refptr<TaskRunner> single_thread_task_runner, | |
391 WaitableEvent* task_signal) { | |
392 EXPECT_FALSE( | |
393 single_thread_task_runner->RunsTasksOnCurrentThread()); | |
394 task_signal->Signal(); | |
395 }, | |
396 single_thread_task_runner, Unretained(task_signals[i].get()))); | |
397 } | |
398 | |
399 for (auto& task_signal : task_signals) | |
400 task_signal->Wait(); | |
401 } | |
402 | |
367 INSTANTIATE_TEST_CASE_P(Parallel, | 403 INSTANTIATE_TEST_CASE_P(Parallel, |
368 TaskSchedulerWorkerPoolImplTest, | 404 TaskSchedulerWorkerPoolImplTest, |
369 ::testing::Values(test::ExecutionMode::PARALLEL)); | 405 ::testing::Values(test::ExecutionMode::PARALLEL)); |
370 INSTANTIATE_TEST_CASE_P(Sequenced, | 406 INSTANTIATE_TEST_CASE_P(Sequenced, |
371 TaskSchedulerWorkerPoolImplTest, | 407 TaskSchedulerWorkerPoolImplTest, |
372 ::testing::Values(test::ExecutionMode::SEQUENCED)); | 408 ::testing::Values(test::ExecutionMode::SEQUENCED)); |
373 INSTANTIATE_TEST_CASE_P( | 409 INSTANTIATE_TEST_CASE_P( |
374 SingleThreaded, | 410 SingleThreaded, |
375 TaskSchedulerWorkerPoolImplTest, | 411 TaskSchedulerWorkerPoolImplTest, |
376 ::testing::Values(test::ExecutionMode::SINGLE_THREADED)); | 412 ::testing::Values(test::ExecutionMode::SINGLE_THREADED)); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 | 796 |
761 // Verify that counts were recorded to the histogram as expected. | 797 // Verify that counts were recorded to the histogram as expected. |
762 const auto* histogram = worker_pool_->num_tasks_before_detach_histogram(); | 798 const auto* histogram = worker_pool_->num_tasks_before_detach_histogram(); |
763 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(0)); | 799 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(0)); |
764 EXPECT_EQ(1, histogram->SnapshotSamples()->GetCount(3)); | 800 EXPECT_EQ(1, histogram->SnapshotSamples()->GetCount(3)); |
765 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10)); | 801 EXPECT_EQ(0, histogram->SnapshotSamples()->GetCount(10)); |
766 } | 802 } |
767 | 803 |
768 } // namespace internal | 804 } // namespace internal |
769 } // namespace base | 805 } // namespace base |
OLD | NEW |