Commit 4bac235c authored by Wez's avatar Wez Committed by Commit Bot

Allow SchedulerWorkerPoolImplTests to wait longer for capacity increase.

Previously the tests would wait up to four times in the
ExpectWorkerCapacityAfterDelay() helper function, which leads to them
flaking sometimes under systems with heavy load, or systems running
under slow emulation, such as QEMU.

We now allow the test to wait indefinitely, provided that the capacity
of the worker pool is stable, or increases.

Bug: 792310
Change-Id: Ida8aa3abbb2d290771f74a7aae4ba7fe5c2176a0
Reviewed-on: https://chromium-review.googlesource.com/809710Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522117}
parent a8a8bbac
......@@ -968,19 +968,16 @@ class TaskSchedulerWorkerPoolBlockingTest
TestTimeouts::tiny_timeout();
}
// Waits up to some amount of time until |worker_pool_|'s worker capacity
// reaches |expected_worker_capacity|.
void ExpectWorkerCapacityAfterDelay(size_t expected_worker_capacity) {
constexpr int kMaxAttempts = 4;
for (int i = 0;
i < kMaxAttempts && worker_pool_->GetWorkerCapacityForTesting() !=
expected_worker_capacity;
++i) {
// Waits indefinitely, until |worker_pool_|'s worker capacity increases to
// |expected_worker_capacity|.
void ExpectWorkerCapacityIncreasesTo(size_t expected_worker_capacity) {
size_t capacity = worker_pool_->GetWorkerCapacityForTesting();
while (capacity != expected_worker_capacity) {
PlatformThread::Sleep(GetWorkerCapacityChangeSleepTime());
size_t new_capacity = worker_pool_->GetWorkerCapacityForTesting();
ASSERT_GE(new_capacity, capacity);
capacity = new_capacity;
}
EXPECT_EQ(worker_pool_->GetWorkerCapacityForTesting(),
expected_worker_capacity);
}
// Unblocks tasks posted by SaturateWithBlockingTasks().
......@@ -1004,7 +1001,7 @@ TEST_P(TaskSchedulerWorkerPoolBlockingTest, ThreadBlockedUnblocked) {
SaturateWithBlockingTasks(GetParam());
if (GetParam().behaves_as == BlockingType::MAY_BLOCK)
ExpectWorkerCapacityAfterDelay(2 * kNumWorkersInWorkerPool);
ExpectWorkerCapacityIncreasesTo(2 * kNumWorkersInWorkerPool);
// A range of possible number of workers is accepted because of
// crbug.com/757897.
EXPECT_GE(worker_pool_->NumberOfWorkersForTesting(),
......@@ -1100,7 +1097,7 @@ TEST_P(TaskSchedulerWorkerPoolBlockingTest, PostBeforeBlocking) {
// tasks we just posted.
thread_can_block.Signal();
if (GetParam().behaves_as == BlockingType::MAY_BLOCK)
ExpectWorkerCapacityAfterDelay(2 * kNumWorkersInWorkerPool);
ExpectWorkerCapacityIncreasesTo(2 * kNumWorkersInWorkerPool);
// Should not block forever.
extra_thread_running.Wait();
......@@ -1119,7 +1116,7 @@ TEST_P(TaskSchedulerWorkerPoolBlockingTest, WorkersIdleWhenOverCapacity) {
SaturateWithBlockingTasks(GetParam());
if (GetParam().behaves_as == BlockingType::MAY_BLOCK)
ExpectWorkerCapacityAfterDelay(2 * kNumWorkersInWorkerPool);
ExpectWorkerCapacityIncreasesTo(2 * kNumWorkersInWorkerPool);
EXPECT_EQ(worker_pool_->GetWorkerCapacityForTesting(),
2 * kNumWorkersInWorkerPool);
// A range of possible number of workers is accepted because of
......@@ -1303,7 +1300,7 @@ TEST_F(TaskSchedulerWorkerPoolBlockingTest,
Unretained(&did_instantiate_will_block), Unretained(&can_return)));
// After a short delay, worker capacity should be incremented.
ExpectWorkerCapacityAfterDelay(kNumWorkersInWorkerPool + 1);
ExpectWorkerCapacityIncreasesTo(kNumWorkersInWorkerPool + 1);
// Wait until the task instantiates a WILL_BLOCK ScopedBlockingCall.
can_instantiate_will_block.Signal();
......
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