fixing flaky tests in mac and windows

This commit is contained in:
matlabbe
2026-05-30 21:28:53 -07:00
parent e8eabc1538
commit 3ecddfb583
6 changed files with 77 additions and 19 deletions
+19 -3
View File
@@ -460,13 +460,29 @@ TEST(ULoggerTest, ThreadIdFilterVector)
ULogger::registerCurrentThread("FilterThread");
OtherThread otherThread;
otherThread.start();
// OtherThread registers itself from inside mainLoopBegin(), which runs
// asynchronously after start(). setTreadIdFilter() resolves names against
// the current registeredThreads_ map, so we have to wait for the other
// thread to register before applying the filter -- otherwise only
// "FilterThread" ends up in the filter set (intermittent failure on slow
// Windows runners).
for(int i = 0; i < 200; ++i)
{
const std::map<std::string, unsigned long> regs = ULogger::getRegisteredThreads();
if(regs.find(otherThread.name()) != regs.end())
{
break;
}
uSleep(10);
}
std::vector<std::string> threadNames;
threadNames.push_back(otherThread.name());
threadNames.push_back("FilterThread");
ULogger::setTreadIdFilter(threadNames);
const std::set<unsigned long>& retrieved = ULogger::getTreadIdFilter();
EXPECT_EQ(retrieved.size(), 2u);
+2 -1
View File
@@ -116,8 +116,9 @@ TEST(USemaphoreTest, AcquireTry)
result = sem.acquireTry();
EXPECT_TRUE(result);
EXPECT_EQ(sem.value(), 0);
// Semaphore is exhausted: the next non-blocking try must fail.
result = sem.acquireTry();
EXPECT_TRUE(result);
EXPECT_FALSE(result);
#else
int result = sem.acquireTry(1);
EXPECT_TRUE(result);