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:
Claude
2026-11-03 14:27:11 +00:00
committed by Dennis Klein
parent f50b1f0e39
commit be400e4752
20 changed files with 446 additions and 800 deletions

View File

@@ -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