flaky thread test on slow mac VM

This commit is contained in:
matlabbe
2026-05-29 09:17:19 -07:00
parent 1c4b838403
commit f49d7318e4
+10 -4
View File
@@ -130,20 +130,26 @@ TEST(UThreadTest, Start)
EXPECT_TRUE(thread.isRunning() || thread.isCreating()); EXPECT_TRUE(thread.isRunning() || thread.isCreating());
// Wait up to 500 ms for mainLoop to actually execute. We can't reliably // Wait up to 1 s for mainLoop to actually execute. We can't reliably
// assert isRunning() at a fixed offset: SimpleThread sleeps ~10 ms then // assert isRunning() at a fixed offset: SimpleThread sleeps ~10 ms then
// self-kills, so on a slow CI VM the thread can already be in kSKilled // self-kills, so on a slow CI VM the thread can already be in kSKilled
// by the time we poll. hasStarted() flips to true on first entry to // by the time we poll. hasStarted() flips to true on first entry to
// mainLoop and stays true, so it's race-free. // mainLoop and stays true, so it's race-free.
UTimer waitForStart; UTimer waitForStart;
while(!thread.hasStarted() && waitForStart.ticks() < 0.5) while(!thread.hasStarted() && waitForStart.ticks() < 1.0)
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
EXPECT_TRUE(thread.hasStarted()); EXPECT_TRUE(thread.hasStarted());
// Give the thread time to finish its single iteration + cleanup. // Poll for cleanup. SimpleThread sleeps ~10 ms then self-kills; on slow
std::this_thread::sleep_for(std::chrono::milliseconds(50)); // CI VMs the kSRunning -> kSKilled -> kSIdle settle can take longer than
// a single fixed sleep, so wait up to 1 s.
UTimer waitForFinish;
while(!(thread.isKilled() || thread.isIdle()) && waitForFinish.ticks() < 1.0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
EXPECT_TRUE(thread.isKilled() || thread.isIdle()); EXPECT_TRUE(thread.isKilled() || thread.isIdle());
thread.join(); thread.join();