This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 0b5b5da6d [util] fix flakiness in threadpool-test
0b5b5da6d is described below
commit 0b5b5da6d30d792915a2e22646a3f554783fd678
Author: Alexey Serbin <[email protected]>
AuthorDate: Thu Mar 13 14:07:45 2025 -0700
[util] fix flakiness in threadpool-test
There were reports about a few test scenarios failing intermittently
with errors like below on a very busy machine:
[ RUN ] ThreadPoolTest.TestThreadPoolWithNoMinimum
/root/Projects/kudu/src/kudu/util/threadpool-test.cc:317: Failure
Expected equality of these values:
0
pool_->num_threads()
Which is: 1
[ RUN ] ThreadPoolTest.TestVariableSizeThreadPool
/root/Projects/kudu/src/kudu/util/threadpool-test.cc:459: Failure
Expected equality of these values:
1
pool_->num_threads()
Which is: 2
This patch fixes the issue, removing implicit assumptions on timings
of events that might not be true in the presence of scheduled anomalies.
This is a follow-up to fc8615c37eb4e28f3cc6bea0fcd5a8732451e883.
Change-Id: I8caed555b2207d25a93105037d77bd579d160550
Reviewed-on: http://gerrit.cloudera.org:8080/22622
Tested-by: Alexey Serbin <[email protected]>
Reviewed-by: Abhishek Chennaka <[email protected]>
---
src/kudu/util/threadpool-test.cc | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/kudu/util/threadpool-test.cc b/src/kudu/util/threadpool-test.cc
index ec637de0e..35708ee0c 100644
--- a/src/kudu/util/threadpool-test.cc
+++ b/src/kudu/util/threadpool-test.cc
@@ -283,12 +283,11 @@ TEST_F(ThreadPoolTest, SchedulerWithNullToken) {
}
TEST_F(ThreadPoolTest, TestThreadPoolWithNoMinimum) {
- constexpr int kIdleTimeoutMs = 1;
ASSERT_OK(RebuildPoolWithBuilder(
ThreadPoolBuilder(kDefaultPoolName)
.set_min_threads(0)
.set_max_threads(3)
- .set_idle_timeout(MonoDelta::FromMilliseconds(kIdleTimeoutMs))));
+ .set_idle_timeout(MonoDelta::FromMilliseconds(1))));
// There are no threads to start with.
ASSERT_TRUE(pool_->num_threads() == 0);
@@ -309,11 +308,10 @@ TEST_F(ThreadPoolTest, TestThreadPoolWithNoMinimum) {
latch.CountDown();
pool_->Wait();
ASSERT_EQ(0, pool_->active_threads_);
- // Wait for more than idle timeout: so threads should be gone since
- // min_threads is set to 0.
- SleepFor(MonoDelta::FromMilliseconds(10 * kIdleTimeoutMs));
- ASSERT_EQ(0, pool_->num_threads());
- ASSERT_EQ(0, pool_->active_threads_);
+ // Wait for the threads to be gone since min_threads is set to 0.
+ ASSERT_EVENTUALLY([&]() {
+ ASSERT_EQ(0, pool_->num_threads());
+ });
pool_->Shutdown();
ASSERT_EQ(0, pool_->num_threads());
}
@@ -426,12 +424,11 @@ TEST_F(ThreadPoolTest, TestRace) {
}
TEST_F(ThreadPoolTest, TestVariableSizeThreadPool) {
- constexpr int kIdleTimeoutMs = 1;
ASSERT_OK(RebuildPoolWithBuilder(
ThreadPoolBuilder(kDefaultPoolName)
.set_min_threads(1)
.set_max_threads(4)
- .set_idle_timeout(MonoDelta::FromMilliseconds(kIdleTimeoutMs))));
+ .set_idle_timeout(MonoDelta::FromMilliseconds(1))));
// There is 1 thread to start with.
ASSERT_EQ(1, pool_->num_threads());
@@ -452,9 +449,11 @@ TEST_F(ThreadPoolTest, TestVariableSizeThreadPool) {
latch.CountDown();
pool_->Wait();
ASSERT_EQ(0, pool_->active_threads_);
- SleepFor(MonoDelta::FromMilliseconds(10 * kIdleTimeoutMs));
- ASSERT_EQ(0, pool_->active_threads_);
- ASSERT_EQ(1, pool_->num_threads());
+ // At some point there should be no more than 'min_threads' idle threads
+ // in the pool.
+ ASSERT_EVENTUALLY([&]() {
+ ASSERT_EQ(1, pool_->num_threads());
+ });
pool_->Shutdown();
ASSERT_EQ(0, pool_->num_threads());
}