Skip to content

Commit

Permalink
update test to reproduce problem
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSylvester committed Jan 15, 2025
1 parent 79d625b commit 9ad6505
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions test/util/async_task.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,25 @@ TEST(AsyncTask, SequencedScheduler) {
}

TEST(AsyncTask, MultipleSequencedSchedulers) {
std::vector<std::shared_ptr<Scheduler>> shedulers;
std::vector<std::shared_ptr<Scheduler>> schedulers;

for (int i = 0; i < 10; ++i) {
std::shared_ptr<Scheduler> 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<std::shared_ptr<Scheduler>> 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>(Scheduler::GetSequenced()));
}

0 comments on commit 9ad6505

Please sign in to comment.