test: let tp_heavy's work finish before destroying each pool

~ThreadPool cancels its workers without draining the queue. Queued
work normally still runs because a worker acts on the cancellation
only when it blocks waiting for work, but that is a race: under load
tp_heavy_repeated_construct_destroy lost some of its 400 tasks in
about one run in ten. Nothing in mergerfs destroys a pool that still
has work: an in-flight readdir keeps its implementation alive and
waits for its own tasks. Wait for the tasks before each pool goes out
of scope instead of relying on the destructor.
This commit is contained in:
Antonio SJ Musumeci 2026-11-29 23:57:06 -05:00 • committed by Antonio S. Musumeci
parent e954f42751
commit 6846ee2674

View file

@ -2450,6 +2450,11 @@ test_tp_heavy_repeated_construct_destroy()
std::this_thread::sleep_for(std::chrono::microseconds(25));
counter.fetch_add(1);
});
// ~ThreadPool cancels its workers without draining the queue,
// so let the work finish before the pool is destroyed.
TEST_CHECK(wait_until([&counter]() { return counter.load() == 400; },
30000));
}
TEST_CHECK(counter.load() == 400);