Commit 7dbda08d authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[ThreadPool] Tighten evaluated TimeDelta of...

[ThreadPool] Tighten evaluated TimeDelta of PooledSingleThreadTaskRunnerManagerCommonTest.PostDelayedTask
and be more flexible with the result.

Bringing it inline with ThreadGroupTestAllExecutionModes.PostDelayedTask

R=etiennep@chromium.org

Bug: 1062845
Change-Id: Icb41d86f1a8185f4cc49bf303842dc5ae6e7a81b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128455
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarEtienne Pierre-Doray <etiennep@chromium.org>
Auto-Submit: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754895}
parent fd47d4d2
...@@ -364,10 +364,7 @@ TEST_P(PooledSingleThreadTaskRunnerManagerCommonTest, PostTaskAfterShutdown) { ...@@ -364,10 +364,7 @@ TEST_P(PooledSingleThreadTaskRunnerManagerCommonTest, PostTaskAfterShutdown) {
// Verify that a Task runs shortly after its delay expires. // Verify that a Task runs shortly after its delay expires.
TEST_P(PooledSingleThreadTaskRunnerManagerCommonTest, PostDelayedTask) { TEST_P(PooledSingleThreadTaskRunnerManagerCommonTest, PostDelayedTask) {
TimeTicks start_time = TimeTicks::Now(); WaitableEvent task_ran(WaitableEvent::ResetPolicy::AUTOMATIC);
WaitableEvent task_ran(WaitableEvent::ResetPolicy::AUTOMATIC,
WaitableEvent::InitialState::NOT_SIGNALED);
auto task_runner = CreateTaskRunner(); auto task_runner = CreateTaskRunner();
// Wait until the task runner is up and running to make sure the test below is // Wait until the task runner is up and running to make sure the test below is
...@@ -377,7 +374,9 @@ TEST_P(PooledSingleThreadTaskRunnerManagerCommonTest, PostDelayedTask) { ...@@ -377,7 +374,9 @@ TEST_P(PooledSingleThreadTaskRunnerManagerCommonTest, PostDelayedTask) {
task_ran.Wait(); task_ran.Wait();
ASSERT_TRUE(!task_ran.IsSignaled()); ASSERT_TRUE(!task_ran.IsSignaled());
// Post a task with a short delay. // Post a task with a short delay.
const TimeTicks start_time = TimeTicks::Now();
EXPECT_TRUE(task_runner->PostDelayedTask( EXPECT_TRUE(task_runner->PostDelayedTask(
FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&task_ran)), FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&task_ran)),
TestTimeouts::tiny_timeout())); TestTimeouts::tiny_timeout()));
...@@ -385,12 +384,12 @@ TEST_P(PooledSingleThreadTaskRunnerManagerCommonTest, PostDelayedTask) { ...@@ -385,12 +384,12 @@ TEST_P(PooledSingleThreadTaskRunnerManagerCommonTest, PostDelayedTask) {
// Wait until the task runs. // Wait until the task runs.
task_ran.Wait(); task_ran.Wait();
// Expect the task to run after its delay expires, but no more than 250 ms // Expect the task to run after its delay expires, but no more than a
// after that. // reasonable amount of time after that (overloaded bots can be slow sometimes
// so give it 10X flexibility).
const TimeDelta actual_delay = TimeTicks::Now() - start_time; const TimeDelta actual_delay = TimeTicks::Now() - start_time;
EXPECT_GE(actual_delay, TestTimeouts::tiny_timeout()); EXPECT_GE(actual_delay, TestTimeouts::tiny_timeout());
EXPECT_LT(actual_delay, EXPECT_LT(actual_delay, 10 * TestTimeouts::tiny_timeout());
TimeDelta::FromMilliseconds(250) + TestTimeouts::tiny_timeout());
} }
// Verify that posting tasks after the single-thread manager is destroyed fails // Verify that posting tasks after the single-thread manager is destroyed fails
......
...@@ -296,7 +296,7 @@ TEST_P(ThreadGroupTestAllExecutionModes, PostDelayedTask) { ...@@ -296,7 +296,7 @@ TEST_P(ThreadGroupTestAllExecutionModes, PostDelayedTask) {
ASSERT_TRUE(!task_ran.IsSignaled()); ASSERT_TRUE(!task_ran.IsSignaled());
// Post a task with a short delay. // Post a task with a short delay.
TimeTicks start_time = TimeTicks::Now(); const TimeTicks start_time = TimeTicks::Now();
EXPECT_TRUE(task_runner->PostDelayedTask( EXPECT_TRUE(task_runner->PostDelayedTask(
FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&task_ran)), FROM_HERE, BindOnce(&WaitableEvent::Signal, Unretained(&task_ran)),
TestTimeouts::tiny_timeout())); TestTimeouts::tiny_timeout()));
......
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