Skip to content

Commit 4cb5380

Browse files
committed
Thread/Scheduler: Stress test
1 parent 147dfac commit 4cb5380

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/Thread/Scheduler.mpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ export namespace CppUtils::UnitTest::Thread::Scheduler
186186
suite.expect(aExecuted.load());
187187
suite.expect(not bExecuted.load());
188188
});
189+
190+
suite.addTest("Stress test with many tasks", [&] {
191+
auto scheduler = CppUtils::Thread::Scheduler{};
192+
const auto numTasks = 100'000uz;
193+
auto executedCount = std::atomic_size_t{0};
194+
195+
for (auto i = 0uz; i < numTasks; ++i)
196+
scheduler.schedule([&] {
197+
executedCount++;
198+
}, std::chrono::milliseconds{CppUtils::Math::getRandomNumberInInterval(0, 9)});
199+
200+
scheduler.waitUntilFinished();
201+
202+
suite.expectEqual(executedCount.load(), numTasks);
203+
});
189204
}};
190205

191206
}

0 commit comments

Comments
 (0)