Commit f9dd52a8 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

tests: fast_teardown: Ensure the discoverer thread is started

parent 5fea91ac
Pipeline #12755 passed with stage
in 28 minutes and 40 seconds
......@@ -26,10 +26,49 @@
#include "medialibrary/IMediaLibrary.h"
#include "mocks/NoopCallback.h"
#include "utils/Filename.h"
#include "compat/Mutex.h"
#include "compat/ConditionVariable.h"
#include <iostream>
#include <condition_variable>
#include <mutex>
#include <unistd.h>
class FastTearDownCb : public mock::NoopCallback
{
public:
FastTearDownCb()
: m_started( false )
{
}
void prepareWait()
{
m_mutex.lock();
m_started = false;
}
virtual void onDiscoveryProgress( const std::string& ) override
{
{
std::lock_guard<compat::Mutex> lock( m_mutex );
m_started = true;
}
m_cond.notify_all();
}
void waitForDiscoveryStarted()
{
std::unique_lock<compat::Mutex> lock( m_mutex, std::adopt_lock );
m_cond.wait_for( lock, std::chrono::seconds{ 5 }, [this](){
return m_started == true;
});
}
private:
compat::Mutex m_mutex;
compat::ConditionVariable m_cond;
bool m_started;
};
int main( int argc, char** argv )
{
......@@ -38,15 +77,18 @@ int main( int argc, char** argv )
std::cerr << "usage: " << argv[0] << " <entrypoint>" << std::endl;
return 1;
}
auto entryPoint = utils::file::toMrl( argv[1] );
for ( auto i = 0; i < 1000; ++i )
{
auto testCb = std::make_unique<mock::NoopCallback>();
auto testCb = std::make_unique<FastTearDownCb>();
std::unique_ptr<medialibrary::IMediaLibrary> ml( NewMediaLibrary() );
ml->initialize( "/tmp/test.db", "/tmp/ml_folder", testCb.get() );
testCb->prepareWait();
ml->start();
ml->discover( argv[1] );
ml->discover( entryPoint );
ml->reload();
testCb->waitForDiscoveryStarted();
}
return 0;
}
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