Commit cfcfba66 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

[TaskScheduler] Clear blocking observer when using WaitableEvent in tests.

When a task posted to TaskScheduler waits on a WaitableEvent, the
pool capacity is automatically incremented after a short delay
(https://cs.chromium.org/chromium/src/base/synchronization/waitable_event_win.cc?l=72&rcl=c60b0bcd6830c32c30128867e55a53f27642df5f and
https://cs.chromium.org/chromium/src/base/synchronization/waitable_event_posix.cc?l=166&rcl=c60b0bcd6830c32c30128867e55a53f27642df5f and
https://cs.chromium.org/chromium/src/base/synchronization/waitable_event_mac.cc?l=115&rcl=c60b0bcd6830c32c30128867e55a53f27642df5f).

This is desirable in production (if a task blocks for a long time,
another thread is created and the number of tasks that are using
the CPU stays constant).

However, it is undesirable when a WaitableEvent is used in
TaskScheduler tests, because it leads to hard to predict changes
of pool capacity.

This CL adds a ScopedClearBlockingObserverForTesting annotation to
all WaitableEvent::Wait that happen in code that tests
SchedulerWorkerPoolImpl, to avoid these hard to predict changes
of pool capacity.

The annotation is not needed when the WaitableEvent::Wait doesn't
happen on a thread managed by SchedulerWorkerPoolImpl, because that
already has no effect on pool capacity.

Bug: 768436
Change-Id: Ie166ca55f914d89c5dd0fe6dad9ae1533e0f6c29
Reviewed-on: https://chromium-review.googlesource.com/1033533Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554732}
parent 0dba0995
...@@ -33,12 +33,12 @@ TestTaskFactory::~TestTaskFactory() { ...@@ -33,12 +33,12 @@ TestTaskFactory::~TestTaskFactory() {
} }
bool TestTaskFactory::PostTask(PostNestedTask post_nested_task, bool TestTaskFactory::PostTask(PostNestedTask post_nested_task,
const Closure& after_task_closure) { OnceClosure after_task_closure) {
AutoLock auto_lock(lock_); AutoLock auto_lock(lock_);
return task_runner_->PostTask( return task_runner_->PostTask(
FROM_HERE, FROM_HERE, BindOnce(&TestTaskFactory::RunTaskCallback, Unretained(this),
BindOnce(&TestTaskFactory::RunTaskCallback, Unretained(this), num_posted_tasks_++, post_nested_task,
num_posted_tasks_++, post_nested_task, after_task_closure)); std::move(after_task_closure)));
} }
void TestTaskFactory::WaitForAllTasksToRun() const { void TestTaskFactory::WaitForAllTasksToRun() const {
...@@ -49,7 +49,7 @@ void TestTaskFactory::WaitForAllTasksToRun() const { ...@@ -49,7 +49,7 @@ void TestTaskFactory::WaitForAllTasksToRun() const {
void TestTaskFactory::RunTaskCallback(size_t task_index, void TestTaskFactory::RunTaskCallback(size_t task_index,
PostNestedTask post_nested_task, PostNestedTask post_nested_task,
const Closure& after_task_closure) { OnceClosure after_task_closure) {
if (post_nested_task == PostNestedTask::YES) if (post_nested_task == PostNestedTask::YES)
PostTask(PostNestedTask::NO, Closure()); PostTask(PostNestedTask::NO, Closure());
...@@ -98,7 +98,7 @@ void TestTaskFactory::RunTaskCallback(size_t task_index, ...@@ -98,7 +98,7 @@ void TestTaskFactory::RunTaskCallback(size_t task_index,
} }
if (!after_task_closure.is_null()) if (!after_task_closure.is_null())
after_task_closure.Run(); std::move(after_task_closure).Run();
} }
} // namespace test } // namespace test
......
...@@ -54,7 +54,7 @@ class TestTaskFactory { ...@@ -54,7 +54,7 @@ class TestTaskFactory {
// - Verify conditions in which the task runs (see potential failures above). // - Verify conditions in which the task runs (see potential failures above).
// - Run |after_task_closure| if it is not null. // - Run |after_task_closure| if it is not null.
bool PostTask(PostNestedTask post_nested_task, bool PostTask(PostNestedTask post_nested_task,
const Closure& after_task_closure); OnceClosure after_task_closure);
// Waits for all tasks posted by PostTask() to start running. It is not // Waits for all tasks posted by PostTask() to start running. It is not
// guaranteed that the tasks have completed their execution when this returns. // guaranteed that the tasks have completed their execution when this returns.
...@@ -65,7 +65,7 @@ class TestTaskFactory { ...@@ -65,7 +65,7 @@ class TestTaskFactory {
private: private:
void RunTaskCallback(size_t task_index, void RunTaskCallback(size_t task_index,
PostNestedTask post_nested_task, PostNestedTask post_nested_task,
const Closure& after_task_closure); OnceClosure after_task_closure);
// Synchronizes access to all members. // Synchronizes access to all members.
mutable Lock lock_; mutable Lock lock_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment