mirror of
https://github.com/meganz/MEGAcmd
synced 2025-08-30 21:35:10 +00:00
have setup not sleep and use intruments event instead
This commit is contained in:
@@ -29,6 +29,11 @@
|
||||
#include "megacmdplatform.h"
|
||||
#include "megacmdversion.h"
|
||||
|
||||
#ifdef MEGACMD_TESTING_CODE
|
||||
#include "../tests/common/Instruments.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define USE_VARARGS
|
||||
#define PREFER_STDARG
|
||||
|
||||
@@ -4185,6 +4190,10 @@ void megacmd()
|
||||
|
||||
LOG_info << "Listening to petitions ... ";
|
||||
|
||||
#ifdef MEGACMD_TESTING_CODE
|
||||
TestInstruments::Instance().fireEvent(TestInstruments::Event::SERVER_ABOUT_TO_START_WAITING_FOR_PETITIONS);
|
||||
#endif
|
||||
|
||||
for (;; )
|
||||
{
|
||||
cm->waitForPetition();
|
||||
|
@@ -64,7 +64,7 @@ public:
|
||||
//
|
||||
enum class Event
|
||||
{
|
||||
SOME_MEGACMD_INSTRUMENT_EVENT,
|
||||
SERVER_ABOUT_TO_START_WAITING_FOR_PETITIONS,
|
||||
};
|
||||
|
||||
typedef std::function<void()> EventCallback;
|
||||
|
@@ -22,25 +22,37 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "Instruments.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
|
||||
class BasicGenericTest : public ::testing::Test
|
||||
{
|
||||
std::thread mServerThread;
|
||||
void SetUp() override
|
||||
{
|
||||
std::thread t([](){
|
||||
mServerThread = std::thread([](){
|
||||
char **args = new char*[2];
|
||||
args[0]=(char *)"argv0_INTEGRATION_TESTS";
|
||||
args[1] = NULL;
|
||||
megacmd::executeServer(1, args);
|
||||
});
|
||||
|
||||
megacmd::sleepSeconds(2); //TODO: have this properly orchestrated
|
||||
using TI = TestInstruments;
|
||||
|
||||
t.detach();
|
||||
std::promise<void> serverWaitingPromise;
|
||||
TI::Instance().onEventOnce(TI::Event::SERVER_ABOUT_TO_START_WAITING_FOR_PETITIONS,
|
||||
[&serverWaitingPromise]() {
|
||||
serverWaitingPromise.set_value();
|
||||
});
|
||||
|
||||
ASSERT_NE(serverWaitingPromise.get_future().wait_for(std::chrono::seconds(10))
|
||||
, std::future_status::timeout);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
megacmd::stopServer();
|
||||
mServerThread.join();
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user