Tweak test timers to deal with Apple's shitty thread scheduling

This commit is contained in:
Jason Rhinelander 2021-08-04 17:48:53 -03:00
parent 1d2246cda8
commit e1d21d3faf
1 changed files with 3 additions and 2 deletions

View File

@ -15,9 +15,10 @@ TEST_CASE("timer test", "[timer][basic]") {
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
wait_for([&] { return ticks.load() > 3; }); wait_for([&] { return ticks.load() > 3; });
{ {
auto elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start).count();
auto lock = catch_lock(); auto lock = catch_lock();
REQUIRE( ticks.load() > 3 ); REQUIRE( ticks.load() > 3 );
REQUIRE( std::chrono::steady_clock::now() - start < 40ms ); REQUIRE( elapsed_ms < 50 );
} }
} }
@ -58,7 +59,7 @@ TEST_CASE("timer squelch", "[timer][squelch]") {
std::atomic<int> ticks2 = 0; std::atomic<int> ticks2 = 0;
auto timer2 = omq.add_timer([&] { auto timer2 = omq.add_timer([&] {
if (first2.exchange(false)) { if (first2.exchange(false)) {
std::this_thread::sleep_for(30ms); std::this_thread::sleep_for(40ms);
done2 = true; done2 = true;
} else if (!done2) { } else if (!done2) {
ticks2++; ticks2++;