Commit 0a4f882a authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

tests: samples: Fix race condition

parent e2b96bae
......@@ -12,17 +12,26 @@ bool MockCallback::waitForParsingComplete()
{
std::unique_lock<std::mutex> lock( m_parsingMutex, std::adopt_lock );
m_done = false;
m_discoveryCompleted = false;
// Wait for a while, generating snapshots can be heavy...
return m_parsingCompleteVar.wait_for( lock, std::chrono::seconds( 30 ), [this]() {
return m_done;
});
}
void MockCallback::onDiscoveryCompleted(const std::string&)
{
std::lock_guard<std::mutex> lock( m_parsingMutex );
m_discoveryCompleted = true;
}
void MockCallback::onParsingStatsUpdated(uint32_t nbParsed, uint32_t nbToParse)
{
if ( nbParsed == nbToParse && nbToParse > 0 )
{
std::lock_guard<std::mutex> lock( m_parsingMutex );
if ( m_discoveryCompleted == false )
return;
m_done = true;
m_parsingCompleteVar.notify_all();
}
......
......@@ -24,7 +24,7 @@ private:
void onFileAdded(MediaPtr) {}
void onFileUpdated(MediaPtr) {}
void onDiscoveryStarted(const std::string&) {}
void onDiscoveryCompleted(const std::string&) {}
void onDiscoveryCompleted(const std::string&);
void onReloadStarted() {}
void onReloadCompleted() {}
void onParsingStatsUpdated(uint32_t nbParsed, uint32_t nbToParse);
......@@ -32,6 +32,7 @@ private:
std::condition_variable m_parsingCompleteVar;
std::mutex m_parsingMutex;
bool m_done;
bool m_discoveryCompleted;
};
class Tests : public ::testing::TestWithParam<const char*>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment