Skip to content

Commit

Permalink
Fix Flaky MixAudio Unit tests (#389)
Browse files Browse the repository at this point in the history
* fixFlakyMixAudioUT
* data race
  • Loading branch information
olofkallander authored Nov 15, 2024
1 parent dbf3b70 commit 83d6acd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions logger/LoggerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ LoggerThread::LoggerThread(const char* logFileName, bool logStdOut, bool logStdE
_lastMaintenanceTime(0),
_thread(new std::thread([this] { this->run(); }))
{
_reOpenLog.test_and_set();
reopenLogFile();
}

void LoggerThread::reopenLogFile()
Expand Down Expand Up @@ -52,6 +50,9 @@ void LoggerThread::run()
concurrency::setThreadName("Logger");
char localTime[timeStringLength];
bool gotLogItem = false;
_reOpenLog.test_and_set();
reopenLogFile();

for (;;)
{
const auto item = _logQueue.front();
Expand All @@ -78,10 +79,12 @@ void LoggerThread::run()
{
if (gotLogItem)
{
if (_logStdOut) {
if (_logStdOut)
{
fflush(stdout);
}
if (_logStdErr) {
if (_logStdErr)
{
fflush(stderr);
}
}
Expand Down Expand Up @@ -238,7 +241,7 @@ void LoggerThread::immediate(std::chrono::system_clock::time_point timestamp,
formatTo(stdout, localTime, logLevel, threadId, message);
fflush(stdout);
}
if (_logStdErr && !std::strcmp(logLevel, "ERROR"))
if (_logStdErr && !std::strcmp(logLevel, "ERROR"))
{
formatTo(stderr, localTime, logLevel, threadId, message);
fflush(stderr);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/FFTanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void analyzeRecording(const std::vector<int16_t>& recording,
for (size_t i = 0; i < frequencies[threadId].size() && i < 50; ++i)
{
if (std::find_if(frequencyPeaks.begin(), frequencyPeaks.end(), [&](double f) {
return std::abs(f - frequencies[threadId][i]) < 90;
return std::abs(f - frequencies[threadId][i]) < f * 0.1;
}) == frequencyPeaks.end())
{
logger::debug("added new freq %.3f", logId, frequencies[threadId][i]);
Expand Down

0 comments on commit 83d6acd

Please sign in to comment.