From 6846ee2674ecaebea15ff8d86839c160426a83ce Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sun, 29 Nov 2026 23:57:06 -0500 Subject: [PATCH] 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. --- tests/tests.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/tests.cpp b/tests/tests.cpp index f786fbc8..18facbd7 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -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);