diff --git a/test/util/async_task.test.cpp b/test/util/async_task.test.cpp index fd58cfd5a3d..1804845f8b3 100644 --- a/test/util/async_task.test.cpp +++ b/test/util/async_task.test.cpp @@ -206,13 +206,25 @@ TEST(AsyncTask, SequencedScheduler) { } TEST(AsyncTask, MultipleSequencedSchedulers) { - std::vector> shedulers; + std::vector> schedulers; - for (int i = 0; i < 10; ++i) { - std::shared_ptr scheduler = Scheduler::GetSequenced(); - EXPECT_TRUE(std::none_of( - shedulers.begin(), shedulers.end(), [&scheduler](const auto &item) { return item == scheduler; })); - shedulers.emplace_back(std::move(scheduler)); + // must match the value in the scheduler + constexpr std::size_t kSchedulersCount = 10; + + for (std::size_t j = 0; j < kSchedulersCount; ++j) { + std::vector> refs(kSchedulersCount); + for (std::size_t i = 0; i < refs.size(); ++i) { + refs[i] = Scheduler::GetSequenced(); + } + refs[j].reset(); + + // Check that exactly N unique schedulers are produced. + // Note that this relies on no other threads requesting schedulers. + for (std::size_t i = 0; i < kSchedulersCount; ++i) { + auto scheduler = Scheduler::GetSequenced(); + EXPECT_TRUE(std::ranges::find(schedulers, scheduler) == schedulers.end()); + schedulers.emplace_back(std::move(scheduler)); + } + EXPECT_EQ(schedulers.front(), Scheduler::GetSequenced()); } - EXPECT_EQ(shedulers.front(), std::shared_ptr(Scheduler::GetSequenced())); }