Skip to content

Commit

Permalink
oops
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSylvester committed Jan 15, 2025
1 parent 8cad10c commit d4730c3
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions test/util/async_task.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,25 +206,22 @@ TEST(AsyncTask, SequencedScheduler) {
}

TEST(AsyncTask, MultipleSequencedSchedulers) {
std::vector<std::shared_ptr<Scheduler>> schedulers;
constexpr std::size_t kSchedulersCount = 10; // must match the value in the scheduler

// must match the value in the scheduler
constexpr std::size_t kSchedulersCount = 10;
std::vector<std::shared_ptr<Scheduler>> schedulers;

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());
// Regression check, the scheduler assignment was previously sensitive to the state of the weak references.
// If expired weak references followed a still-valid one, both after the last-used index, the index would
// be incremented multiple times.
auto temp = Scheduler::GetSequenced();
temp = Scheduler::GetSequenced();

// 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());
}

0 comments on commit d4730c3

Please sign in to comment.