mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 21:21:37 +00:00
test: run multi-process tests with one harness
- Add test::RunDevices(): starts the devices with the same session, transport, shm options and channel config, with a deadline per run - Add the TestDevice base: Check() fails the device, Succeed() prints a marker with the transport name that the harness verifies - Make the protocol, poller and transfer-timeout devices check their own results and drop the InitTask() sleeps - Replace EXPECT_EXIT() and the copied launch code in the protocol, poller and transfer-timeout tests - A device that uses the wrong transport now fails the test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
52
test/helper/devices/TestDevice.h
Normal file
52
test/helper/devices/TestDevice.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_TEST_TESTDEVICE_H
|
||||
#define FAIR_MQ_TEST_TESTDEVICE_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
|
||||
#include <fairlogger/Logger.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
/// Printed by a test device that has done all its checks. The test harness
|
||||
/// expects it followed by the name of the transport that the device used.
|
||||
constexpr std::string_view kSuccessMarker = "test device succeeded, transport: ";
|
||||
|
||||
/// Base class of the devices in runTestDevice.
|
||||
class TestDevice : public Device
|
||||
{
|
||||
protected:
|
||||
/// Report success; call it as the last step of the test.
|
||||
void Succeed() const { LOG(info) << kSuccessMarker << GetTransportName(); }
|
||||
|
||||
/// Throw if the condition is false. The device then goes to the Error
|
||||
/// state and exits with a non-zero exit code.
|
||||
static void Check(bool condition, std::string_view what)
|
||||
{
|
||||
if (!condition) {
|
||||
throw std::runtime_error(std::string("check failed: ").append(what));
|
||||
}
|
||||
}
|
||||
|
||||
/// The content of a message as a string.
|
||||
static auto AsString(Message const& msg) -> std::string
|
||||
{
|
||||
return {static_cast<char const*>(msg.GetData()), msg.GetSize()};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
#endif /* FAIR_MQ_TEST_TESTDEVICE_H */
|
||||
@@ -9,52 +9,35 @@
|
||||
#ifndef FAIR_MQ_TEST_PAIRLEFT_H
|
||||
#define FAIR_MQ_TEST_PAIRLEFT_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <thread>
|
||||
#include "TestDevice.h"
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
class PairLeft : public Device
|
||||
class PairLeft : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
int counter{0};
|
||||
|
||||
// Simple empty message ping pong
|
||||
// empty message ping pong
|
||||
auto msg1(NewMessageFor("data", 0));
|
||||
if (Send(msg1, "data") >= 0) counter++;
|
||||
Check(Send(msg1, "data") >= 0, "send empty message 1");
|
||||
auto msg2(NewMessageFor("data", 0));
|
||||
if (Receive(msg2, "data") >= 0) counter++;
|
||||
Check(Receive(msg2, "data") >= 0, "receive empty message 2");
|
||||
auto msg3(NewMessageFor("data", 0));
|
||||
if (Send(msg3, "data") >= 0) counter++;
|
||||
Check(Send(msg3, "data") >= 0, "send empty message 3");
|
||||
auto msg4(NewMessageFor("data", 0));
|
||||
if (Receive(msg4, "data") >= 0) counter++;
|
||||
if (counter == 4) LOG(info) << "Simple empty message ping pong successfull";
|
||||
Check(Receive(msg4, "data") >= 0, "receive empty message 4");
|
||||
|
||||
// Simple message with short text data
|
||||
// message with short text data
|
||||
auto msg5(NewSimpleMessageFor("data", 0, "testdata1234"));
|
||||
if (Send(msg5, "data") >= 0) counter++;
|
||||
Check(Send(msg5, "data") == 12, "send text message");
|
||||
auto msg6(NewMessageFor("data", 0));
|
||||
auto ret = Receive(msg6, "data");
|
||||
if (ret > 0) {
|
||||
auto content = std::string{static_cast<char*>(msg6->GetData()), msg6->GetSize()};
|
||||
LOG(info) << ret << ", " << msg6->GetSize() << ", '" << content << "'";
|
||||
if (msg6->GetSize() == static_cast<std::size_t>(ret) && content == "testdata1234") counter++;
|
||||
}
|
||||
if (counter == 6) LOG(info) << "Simple message with short text data successfull";
|
||||
Check(Receive(msg6, "data") == 12, "receive text message");
|
||||
Check(AsString(*msg6) == "testdata1234", "text message content");
|
||||
|
||||
assert(counter == 6);
|
||||
if (counter == 6) LOG(info) << "PAIR test successfull.";
|
||||
};
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
@@ -9,49 +9,35 @@
|
||||
#ifndef FAIR_MQ_TEST_PAIRRIGHT_H
|
||||
#define FAIR_MQ_TEST_PAIRRIGHT_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include "TestDevice.h"
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
class PairRight : public Device
|
||||
class PairRight : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
int counter{0};
|
||||
|
||||
// Simple empty message ping pong
|
||||
// empty message ping pong
|
||||
auto msg1(NewMessageFor("data", 0));
|
||||
if (Receive(msg1, "data") >= 0) counter++;
|
||||
Check(Receive(msg1, "data") >= 0, "receive empty message 1");
|
||||
auto msg2(NewMessageFor("data", 0));
|
||||
if (Send(msg2, "data") >= 0) counter++;
|
||||
Check(Send(msg2, "data") >= 0, "send empty message 2");
|
||||
auto msg3(NewMessageFor("data", 0));
|
||||
if (Receive(msg3, "data") >= 0) counter++;
|
||||
Check(Receive(msg3, "data") >= 0, "receive empty message 3");
|
||||
auto msg4(NewMessageFor("data", 0));
|
||||
if (Send(msg4, "data") >= 0) counter++;
|
||||
if (counter == 4) LOG(info) << "Simple empty message ping pong successfull";
|
||||
Check(Send(msg4, "data") >= 0, "send empty message 4");
|
||||
|
||||
// Simple message with short text data
|
||||
// message with short text data
|
||||
auto msg5(NewMessageFor("data", 0));
|
||||
auto ret = Receive(msg5, "data");
|
||||
if (ret > 0) {
|
||||
auto content = std::string{static_cast<char*>(msg5->GetData()), msg5->GetSize()};
|
||||
LOG(info) << ret << ", " << msg5->GetSize() << ", '" << content << "'";
|
||||
if (msg5->GetSize() == static_cast<std::size_t>(ret) && content == "testdata1234") counter++;
|
||||
}
|
||||
Check(Receive(msg5, "data") == 12, "receive text message");
|
||||
Check(AsString(*msg5) == "testdata1234", "text message content");
|
||||
auto msg6(NewSimpleMessageFor("data", 0, "testdata1234"));
|
||||
if (Send(msg6, "data") >= 0) counter++;
|
||||
if (counter == 6) LOG(info) << "Simple message with short text data successfull";
|
||||
};
|
||||
Check(Send(msg6, "data") == 12, "send text message");
|
||||
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
@@ -9,117 +9,59 @@
|
||||
#ifndef FAIR_MQ_TEST_POLLIN_H
|
||||
#define FAIR_MQ_TEST_POLLIN_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include "TestDevice.h"
|
||||
|
||||
#include <fairmq/ProgOptions.h>
|
||||
|
||||
#include <fairlogger/Logger.h>
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
class PollIn : public Device
|
||||
/// Polls two channels until a message arrived on each.
|
||||
/// poll-type 0: poll a vector of sub-channels; 1: poll by channel names.
|
||||
class PollIn : public TestDevice
|
||||
{
|
||||
public:
|
||||
PollIn()
|
||||
: fPollType(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
fPollType = fConfig->GetProperty<int>("poll-type");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
Check(fPollType == 0 || fPollType == 1, "poll-type is 0 or 1");
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
vector<Channel*> chans;
|
||||
|
||||
chans.push_back(&GetChannel("data1", 0));
|
||||
chans.push_back(&GetChannel("data2", 0));
|
||||
|
||||
PollerPtr poller = nullptr;
|
||||
|
||||
if (fPollType == 0)
|
||||
{
|
||||
PollerPtr poller;
|
||||
if (fPollType == 0) {
|
||||
std::vector<Channel*> chans{&GetChannel("data1", 0), &GetChannel("data2", 0)};
|
||||
poller = NewPoller(chans);
|
||||
}
|
||||
else if (fPollType == 1)
|
||||
{
|
||||
} else {
|
||||
poller = NewPoller("data1", "data2");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "wrong poll type provided: " << fPollType;
|
||||
}
|
||||
|
||||
auto checkInput = [&](int index, std::string const& name) {
|
||||
return fPollType == 0 ? poller->CheckInput(index) : poller->CheckInput(name, 0);
|
||||
};
|
||||
|
||||
bool arrived1 = false;
|
||||
bool arrived2 = false;
|
||||
bool bothArrived = false;
|
||||
|
||||
MessagePtr msg1(NewMessage());
|
||||
MessagePtr msg2(NewMessage());
|
||||
|
||||
while (!bothArrived)
|
||||
{
|
||||
while (!arrived1 || !arrived2) {
|
||||
poller->Poll(100);
|
||||
|
||||
if (fPollType == 0)
|
||||
{
|
||||
if (poller->CheckInput(0))
|
||||
{
|
||||
LOG(debug) << "CheckInput(0) triggered";
|
||||
if (Receive(msg1, "data1", 0) >= 0)
|
||||
{
|
||||
arrived1 = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (poller->CheckInput(1))
|
||||
{
|
||||
LOG(debug) << "CheckInput(1) triggered";
|
||||
if (Receive(msg2, "data2", 0) >= 0)
|
||||
{
|
||||
arrived2 = true;
|
||||
}
|
||||
}
|
||||
if (checkInput(0, "data1")) {
|
||||
auto msg = NewMessage();
|
||||
arrived1 = arrived1 || Receive(msg, "data1", 0) >= 0;
|
||||
}
|
||||
else if (fPollType == 1)
|
||||
{
|
||||
if (poller->CheckInput("data1", 0))
|
||||
{
|
||||
LOG(debug) << "CheckInput(\"data1\", 0) triggered";
|
||||
if (Receive(msg1, "data1", 0) >= 0)
|
||||
{
|
||||
arrived1 = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (poller->CheckInput("data2", 0))
|
||||
{
|
||||
LOG(debug) << "CheckInput(\"data2\", 0) triggered";
|
||||
if (Receive(msg2, "data2", 0) >= 0)
|
||||
{
|
||||
arrived2 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (arrived1 && arrived2)
|
||||
{
|
||||
bothArrived = true;
|
||||
LOG(info) << "POLL test successfull";
|
||||
if (checkInput(1, "data2")) {
|
||||
auto msg = NewMessage();
|
||||
arrived2 = arrived2 || Receive(msg, "data2", 0) >= 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Succeed();
|
||||
}
|
||||
|
||||
private:
|
||||
int fPollType;
|
||||
int fPollType = 0;
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
@@ -9,27 +9,23 @@
|
||||
#ifndef FAIR_MQ_TEST_POLLOUT_H
|
||||
#define FAIR_MQ_TEST_POLLOUT_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <thread>
|
||||
#include "TestDevice.h"
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
class PollOut : public Device
|
||||
class PollOut : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto msg1 = NewMessage();
|
||||
Check(Send(msg1, "data1") >= 0, "send on data1");
|
||||
auto msg2 = NewMessage();
|
||||
Send(msg1, "data1");
|
||||
Send(msg2, "data2");
|
||||
};
|
||||
Check(Send(msg2, "data2") >= 0, "send on data2");
|
||||
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
@@ -9,60 +9,32 @@
|
||||
#ifndef FAIR_MQ_TEST_PUB_H
|
||||
#define FAIR_MQ_TEST_PUB_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include "TestDevice.h"
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
class Pub : public Device
|
||||
/// Publishes one message after both Sub devices report that they are ready,
|
||||
/// then waits for an ack from each.
|
||||
class Pub : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto ready1 = NewMessage();
|
||||
auto ready2 = NewMessage();
|
||||
auto r1 = Receive(ready1, "control");
|
||||
auto r2 = Receive(ready2, "control");
|
||||
if (r1 >= 0 && r2 >= 0)
|
||||
{
|
||||
LOG(info) << "Received both ready signals, proceeding to publish data";
|
||||
|
||||
auto msg = NewMessage();
|
||||
auto d1 = Send(msg, "data");
|
||||
if (d1 >= 0)
|
||||
{
|
||||
LOG(info) << "Sent data: d1 = " << d1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Failed sending data: d1 = " << d1;
|
||||
}
|
||||
|
||||
auto ack1 = NewMessage();
|
||||
auto ack2 = NewMessage();
|
||||
auto a1 = Receive(ack1, "control");
|
||||
auto a2 = Receive(ack2, "control");
|
||||
if (a1 >= 0 && a2 >= 0)
|
||||
{
|
||||
LOG(info) << "PUB-SUB test successfull";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Failed receiving ack signal: a1 = " << a1 << ", a2 = " << a2;
|
||||
}
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
auto ready = NewMessage();
|
||||
Check(Receive(ready, "control") >= 0, "receive ready signal");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Failed receiving ready signal: r1 = " << r1 << ", r2 = " << r2;
|
||||
|
||||
auto msg = NewMessage();
|
||||
Check(Send(msg, "data") >= 0, "publish data");
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
auto ack = NewMessage();
|
||||
Check(Receive(ack, "control") >= 0, "receive ack");
|
||||
}
|
||||
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -9,48 +9,24 @@
|
||||
#ifndef FAIR_MQ_TEST_PULL_H
|
||||
#define FAIR_MQ_TEST_PULL_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <thread>
|
||||
#include "TestDevice.h"
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Pull : public Device
|
||||
class Pull : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
int counter = 0;
|
||||
|
||||
auto msg1 = NewMessageFor("data", 0);
|
||||
|
||||
if (Receive(msg1, "data") >= 0) {
|
||||
++counter;
|
||||
}
|
||||
|
||||
Check(Receive(msg1, "data") == 0, "receive empty message");
|
||||
auto msg2 = NewMessageFor("data", 0);
|
||||
Check(Receive(msg2, "data") == 12, "receive text message");
|
||||
Check(AsString(*msg2) == "testdata1234", "text message content");
|
||||
|
||||
auto ret = Receive(msg2, "data");
|
||||
if (ret >= 0) {
|
||||
auto content = std::string{static_cast<char*>(msg2->GetData()), msg2->GetSize()};
|
||||
LOG(info) << "Transferred " << static_cast<std::size_t>(ret) << " bytes, msg size: " << msg2->GetSize() << ", content: " << content;
|
||||
if (msg2->GetSize() == static_cast<std::size_t>(ret) && content == "testdata1234") {
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
|
||||
if (counter == 2) {
|
||||
LOG(info) << "PUSH-PULL test successfull";
|
||||
}
|
||||
};
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
@@ -9,29 +9,23 @@
|
||||
#ifndef FAIR_MQ_TEST_PUSH_H
|
||||
#define FAIR_MQ_TEST_PUSH_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <thread>
|
||||
#include "TestDevice.h"
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
class Push : public Device
|
||||
class Push : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
// empty message
|
||||
auto msg1 = NewMessageFor("data", 0);
|
||||
Send(msg1, "data");
|
||||
// message with short text data
|
||||
Check(Send(msg1, "data") == 0, "send empty message");
|
||||
auto msg2(NewSimpleMessageFor("data", 0, "testdata1234"));
|
||||
Send(msg2, "data");
|
||||
};
|
||||
Check(Send(msg2, "data") == 12, "send text message");
|
||||
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
@@ -9,56 +9,27 @@
|
||||
#ifndef FAIR_MQ_TEST_REP_H
|
||||
#define FAIR_MQ_TEST_REP_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <thread>
|
||||
#include "TestDevice.h"
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
class Rep : public Device
|
||||
/// Answers two requests (one from each Req device).
|
||||
class Rep : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
bool check(signed long ret, const fair::mq::MessagePtr& msg)
|
||||
{
|
||||
auto content = std::string{static_cast<char*>(msg->GetData()), msg->GetSize()};
|
||||
LOG(info) << "Transferred " << static_cast<std::size_t>(ret) << " bytes, msg size: " << msg->GetSize() << ", content: " << content;
|
||||
return msg->GetSize() == static_cast<std::size_t>(ret) && content == "request";
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
int counter = 0;
|
||||
auto req1 = NewMessage();
|
||||
auto ret1 = Receive(req1, "data");
|
||||
if (ret1 >= 0) {
|
||||
LOG(info) << "Received request 1";
|
||||
if (check(ret1, req1)) {
|
||||
++counter;
|
||||
}
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
auto request = NewMessage();
|
||||
Check(Receive(request, "data") == 7, "receive request");
|
||||
Check(AsString(*request) == "request", "request content");
|
||||
auto reply = NewSimpleMessageFor("data", 0, "reply");
|
||||
Send(reply, "data");
|
||||
}
|
||||
auto req2 = NewMessage();
|
||||
auto ret2 = Receive(req2, "data");
|
||||
if (ret2 >= 0) {
|
||||
LOG(info) << "Received request 2";
|
||||
if (check(ret2, req2)) {
|
||||
++counter;
|
||||
}
|
||||
auto reply = NewSimpleMessageFor("data", 0, "reply");
|
||||
Send(reply, "data");
|
||||
Check(Send(reply, "data") == 5, "send reply");
|
||||
}
|
||||
|
||||
if (counter == 2) {
|
||||
LOG(info) << "REQ-REP test successfull";
|
||||
}
|
||||
};
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
@@ -9,36 +9,25 @@
|
||||
#ifndef FAIR_MQ_TEST_REQ_H
|
||||
#define FAIR_MQ_TEST_REQ_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <thread>
|
||||
#include "TestDevice.h"
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
class Req : public Device
|
||||
class Req : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
auto request = NewSimpleMessageFor("data", 0, "request");
|
||||
Send(request, "data");
|
||||
Check(Send(request, "data") == 7, "send request");
|
||||
|
||||
auto reply = NewMessage();
|
||||
if (Receive(reply, "data") >= 0) {
|
||||
LOG(info) << "received reply";
|
||||
auto content = std::string{static_cast<char*>(reply->GetData()), reply->GetSize()};
|
||||
LOG(info) << "Transferred reply of size: " << reply->GetSize() << ", content: " << content;
|
||||
if (content != "reply") {
|
||||
ChangeStateOrThrow(Transition::ErrorFound);
|
||||
}
|
||||
}
|
||||
};
|
||||
Check(Receive(reply, "data") == 5, "receive reply");
|
||||
Check(AsString(*reply) == "reply", "reply content");
|
||||
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
@@ -9,54 +9,34 @@
|
||||
#ifndef FAIR_MQ_TEST_SUB_H
|
||||
#define FAIR_MQ_TEST_SUB_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include "TestDevice.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
class Sub : public Device
|
||||
class Sub : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto InitTask() -> void override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
}
|
||||
|
||||
auto Run() -> void override
|
||||
{
|
||||
// A pub socket drops messages for a subscriber until the subscription
|
||||
// has reached it. The connect is done, but the subscription can still
|
||||
// be in flight: give it time before the ready signal.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
|
||||
auto ready = NewMessage();
|
||||
auto r1 = Send(ready, "control");
|
||||
if (r1 >= 0)
|
||||
{
|
||||
LOG(info) << "Sent first control signal";
|
||||
auto msg = NewMessage();
|
||||
auto d1 = Receive(msg, "data");
|
||||
if (d1 >= 0)
|
||||
{
|
||||
LOG(info) << "Received data";
|
||||
auto ack = NewMessage();
|
||||
auto a1 = Send(ack, "control");
|
||||
if (a1 >= 0)
|
||||
{
|
||||
LOG(info) << "Sent second control signal";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Failed sending ack signal: a1 = " << a1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Failed receiving data: d1 = " << d1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Failed sending ready signal: r1 = " << r1;
|
||||
}
|
||||
Check(Send(ready, "control") >= 0, "send ready signal");
|
||||
|
||||
auto msg = NewMessage();
|
||||
Check(Receive(msg, "data") >= 0, "receive data");
|
||||
|
||||
auto ack = NewMessage();
|
||||
Check(Send(ack, "control") >= 0, "send ack");
|
||||
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -9,150 +9,44 @@
|
||||
#ifndef FAIR_MQ_TEST_TRANSFERTIMEOUT_H
|
||||
#define FAIR_MQ_TEST_TRANSFERTIMEOUT_H
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include "TestDevice.h"
|
||||
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <string>
|
||||
|
||||
namespace fair::mq::test
|
||||
{
|
||||
|
||||
using namespace fair::mq;
|
||||
|
||||
class TransferTimeout : public Device
|
||||
/// Sends and receives on channels without a peer. Each transfer must end
|
||||
/// with TransferCode::timeout, for a timeout of 200 ms and of 0 ms.
|
||||
class TransferTimeout : public TestDevice
|
||||
{
|
||||
protected:
|
||||
auto Run() -> void override
|
||||
{
|
||||
bool sendMsgCancelingAfter200ms = false;
|
||||
bool receiveMsgCancelingAfter200ms = false;
|
||||
auto const timeout = static_cast<int64_t>(TransferCode::timeout);
|
||||
|
||||
bool sendMsgCancelingAfter0ms = false;
|
||||
bool receiveMsgCancelingAfter0ms = false;
|
||||
for (int ms : {200, 0}) {
|
||||
auto const suffix = " (" + std::to_string(ms) + " ms)";
|
||||
|
||||
bool send1PartCancelingAfter200ms = false;
|
||||
bool receive1PartCancelingAfter200ms = false;
|
||||
auto msgOut(NewMessage());
|
||||
auto msgIn(NewMessage());
|
||||
Check(Send(msgOut, "data-out", 0, ms) == timeout, "send msg times out" + suffix);
|
||||
Check(Receive(msgIn, "data-in", 0, ms) == timeout, "receive msg times out" + suffix);
|
||||
|
||||
bool send1PartCancelingAfter0ms = false;
|
||||
bool receive1PartCancelingAfter0ms = false;
|
||||
|
||||
bool send2PartsCancelingAfter200ms = false;
|
||||
bool receive2PartsCancelingAfter200ms = false;
|
||||
|
||||
bool send2PartsCancelingAfter0ms = false;
|
||||
bool receive2PartsCancelingAfter0ms = false;
|
||||
|
||||
MessagePtr msg1(NewMessage());
|
||||
MessagePtr msg2(NewMessage());
|
||||
|
||||
if (Send(msg1, "data-out", 0, 200) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "send msg canceled (200ms)";
|
||||
sendMsgCancelingAfter200ms = true;
|
||||
} else {
|
||||
LOG(error) << "send msg did not cancel (200ms)";
|
||||
for (int numParts : {1, 2}) {
|
||||
auto const what = std::to_string(numParts) + " part(s) times out" + suffix;
|
||||
Parts partsOut;
|
||||
for (int i = 0; i < numParts; ++i) {
|
||||
partsOut.AddPart(NewMessage(10));
|
||||
}
|
||||
Parts partsIn;
|
||||
Check(Send(partsOut, "data-out", 0, ms) == timeout, "send " + what);
|
||||
Check(Receive(partsIn, "data-in", 0, ms) == timeout, "receive " + what);
|
||||
}
|
||||
}
|
||||
|
||||
if (Receive(msg2, "data-in", 0, 200) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "receive msg canceled (200ms)";
|
||||
receiveMsgCancelingAfter200ms = true;
|
||||
} else {
|
||||
LOG(error) << "receive msg did not cancel (200ms)";
|
||||
}
|
||||
|
||||
if (Send(msg1, "data-out", 0, 0) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "send msg canceled (0ms)";
|
||||
sendMsgCancelingAfter0ms = true;
|
||||
} else {
|
||||
LOG(error) << "send msg did not cancel (0ms)";
|
||||
}
|
||||
|
||||
if (Receive(msg2, "data-in", 0, 0) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "receive msg canceled (0ms)";
|
||||
receiveMsgCancelingAfter0ms = true;
|
||||
} else {
|
||||
LOG(error) << "receive msg did not cancel (0ms)";
|
||||
}
|
||||
|
||||
Parts parts1;
|
||||
parts1.AddPart(NewMessage(10));
|
||||
Parts parts2;
|
||||
|
||||
if (Send(parts1, "data-out", 0, 200) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "send 1 part canceled (200ms)";
|
||||
send1PartCancelingAfter200ms = true;
|
||||
} else {
|
||||
LOG(error) << "send 1 part did not cancel (200ms)";
|
||||
}
|
||||
|
||||
if (Receive(parts2, "data-in", 0, 200) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "receive 1 part canceled (200ms)";
|
||||
receive1PartCancelingAfter200ms = true;
|
||||
} else {
|
||||
LOG(error) << "receive 1 part did not cancel (200ms)";
|
||||
}
|
||||
|
||||
if (Send(parts1, "data-out", 0, 0) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "send 1 part canceled (0ms)";
|
||||
send1PartCancelingAfter0ms = true;
|
||||
} else {
|
||||
LOG(error) << "send 1 part did not cancel (0ms)";
|
||||
}
|
||||
|
||||
if (Receive(parts2, "data-in", 0, 0) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "receive 1 part canceled (0ms)";
|
||||
receive1PartCancelingAfter0ms = true;
|
||||
} else {
|
||||
LOG(error) << "receive 1 part did not cancel (0ms)";
|
||||
}
|
||||
|
||||
Parts parts3;
|
||||
parts3.AddPart(NewMessage(10));
|
||||
parts3.AddPart(NewMessage(10));
|
||||
Parts parts4;
|
||||
|
||||
if (Send(parts3, "data-out", 0, 200) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "send 2 parts canceled (200ms)";
|
||||
send2PartsCancelingAfter200ms = true;
|
||||
} else {
|
||||
LOG(error) << "send 2 parts did not cancel (200ms)";
|
||||
}
|
||||
|
||||
if (Receive(parts4, "data-in", 0, 200) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "receive 2 parts canceled (200ms)";
|
||||
receive2PartsCancelingAfter200ms = true;
|
||||
} else {
|
||||
LOG(error) << "receive 2 parts did not cancel (200ms)";
|
||||
}
|
||||
|
||||
if (Send(parts3, "data-out", 0, 0) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "send 2 parts canceled (0ms)";
|
||||
send2PartsCancelingAfter0ms = true;
|
||||
} else {
|
||||
LOG(error) << "send 2 parts did not cancel (0ms)";
|
||||
}
|
||||
|
||||
if (Receive(parts4, "data-in", 0, 0) == static_cast<int>(TransferCode::timeout)) {
|
||||
LOG(info) << "receive 2 parts canceled (0ms)";
|
||||
receive2PartsCancelingAfter0ms = true;
|
||||
} else {
|
||||
LOG(error) << "receive 2 parts did not cancel (0ms)";
|
||||
}
|
||||
|
||||
if (sendMsgCancelingAfter200ms &&
|
||||
receiveMsgCancelingAfter200ms &&
|
||||
sendMsgCancelingAfter0ms &&
|
||||
receiveMsgCancelingAfter0ms &&
|
||||
send1PartCancelingAfter200ms &&
|
||||
receive1PartCancelingAfter200ms &&
|
||||
send1PartCancelingAfter0ms &&
|
||||
receive1PartCancelingAfter0ms &&
|
||||
send2PartsCancelingAfter200ms &&
|
||||
receive2PartsCancelingAfter200ms &&
|
||||
send2PartsCancelingAfter0ms &&
|
||||
receive2PartsCancelingAfter0ms)
|
||||
{
|
||||
LOG(info) << "Transfer timeout test successfull";
|
||||
}
|
||||
};
|
||||
Succeed();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq::test
|
||||
|
||||
Reference in New Issue
Block a user