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