Files
thehub/testing/api/BlackBoxTest.h
T

89 lines
2.7 KiB
C++
Raw Permalink Normal View History

2019-05-24 23:32:20 +02:00
#ifndef BLACKBOXTEST_H
#define BLACKBOXTEST_H
#include <QtTest/QtTest>
#include <QObject>
#include <NetworkConnection.h>
2019-05-25 14:31:36 +02:00
#include <NetworkManager.h>
2019-05-24 23:32:20 +02:00
#include <APIProtocol.h>
#include <WorkerThreads.h>
#include <Message.h>
2019-09-02 23:35:43 +02:00
#include <functional>
2019-05-24 23:32:20 +02:00
class QProcess;
class NetworkManager;
class BlackBoxTest : public QObject
{
Q_OBJECT
public:
BlackBoxTest(QObject *parent = nullptr);
static void setHubExecutable(const QString &path);
protected slots:
void cleanup(); // called after each test to clean up the started hubs
protected:
enum Connect { ConnectHubs, Standalone };
/**
* Start as sub-processes one or more Hub instances.
* This method will start the hubs without any history (just genesis)
* and on the RegTest chain.
* Note that you can only call this method once a test.
*/
2019-05-24 23:32:20 +02:00
void startHubs(int amount = 1, Connect connect = ConnectHubs);
2019-06-16 00:23:09 +02:00
/**
* Feed a blockchain we prepared to the target hub.
*
* This method starts a new Hub with a known blockchain and connects to \a hubIndex
* and waits until that hub is synchronized with the new one.
*
2019-08-03 16:50:22 +02:00
* For block 112 the tx-heights are; 81 181 1019 1857 2694 3531 4368 5202 6042 6879
2019-06-16 00:23:09 +02:00
*/
void feedDefaultBlocksToHub(int hubIndex);
2020-05-19 17:39:21 +02:00
/// overloaded convenience call mirring the serviceId fromt the \a message
Message waitForReply(int hub, const Message &message, int messageId, int timeout = 30000);
/**
* Send a message to hub-by-index and wait for a reply.
* Note that the reply can be of the API service error message type as well as the
* expected message.
*
* \param hub the index of the hub, started previously using startHubs()
* \param message the actual message to send.
* \param messageId the reply-message-id we expect.
* \param timeout max waiting time in milliseconds.
*/
2020-05-19 17:39:21 +02:00
Message waitForReply(int hubId, const Message &message, Api::ServiceIds serviceId, int messageId, int timeout = 30000);
2019-05-24 23:32:20 +02:00
2019-09-02 23:35:43 +02:00
/// Checks if all hubs reached at least the designated height
bool waitForHeight(int height);
2019-05-24 23:32:20 +02:00
struct Hub {
QProcess *proc;
int p2pPort = 0;
int apiPort = 0;
std::deque<Message> messages;
void addMessage(const Message &message);
2019-06-16 00:23:09 +02:00
QAtomicInt m_waitForServiceId;
QAtomicInt m_waitForMessageId;
QAtomicInt m_waitForMessageId2;
2019-05-24 23:32:20 +02:00
QAtomicPointer<Message> m_foundMessage;
};
std::vector<Hub> m_hubs;
std::vector<NetworkConnection> con;
WorkerThreads m_workers;
2019-05-25 14:31:36 +02:00
NetworkManager m_network;
2019-05-24 23:32:20 +02:00
QString m_currentTest;
QString m_baseDir;
static QString s_hubPath;
2019-09-02 23:35:43 +02:00
std::vector<std::function<void(const EndPoint&)> > m_onConnectCallbacks;
2019-05-24 23:32:20 +02:00
};
#endif