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

@@ -6,82 +6,46 @@
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include "runner.h"
#include <fairmq/tools/Unique.h>
#include <fairmq/tools/Process.h>
#include <fairmq/tools/Strings.h>
#include <helper/Devices.h>
#include <helper/Transport.h>
#include <gtest/gtest.h>
#include <cstdio> // std::remove
#include <sstream> // std::stringstream
#include <thread>
#include <string>
namespace
{
using namespace std;
using namespace fair::mq::test;
using namespace fair::mq::tools;
auto RunPushPull(string transport, const string& extraDeviceCmdArgs) -> void
auto RunPushPull(string const& transport, string const& extraArgs) -> void
{
size_t session(fair::mq::tools::UuidHash());
string ipcFile("/tmp/fmq_" + to_string(session) + "_data_" + transport);
string address("ipc://" + ipcFile);
IpcAddress const address("push_pull");
auto push = execute_result{"", 100};
thread push_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id push_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=push,method=bind,address=" << address;
push = execute(cmd.str(), "[PUSH]");
});
auto const results = RunDevices({
{"push_" + transport, "name=data,type=push,method=bind,address=" + address.str()},
{"pull_" + transport, "name=data,type=pull,method=connect,address=" + address.str()},
}, RunOptions(transport, extraArgs));
auto pull = execute_result{"", 100};
thread pull_thread([&]() {
stringstream cmd;
cmd << runTestDevice
<< " --id pull_" << transport
<< " --control static"
<< " --transport " << transport
<< " --shm-monitor true"
<< " --shm-segment-size 100000000"
<< " --session " << session
<< " --color false"
<< extraDeviceCmdArgs
<< " --channel-config name=data,type=pull,method=connect,address=" << address;
pull = execute(cmd.str(), "[PULL]");
});
push_thread.join();
pull_thread.join();
cerr << push.console_out << pull.console_out;
std::remove(ipcFile.c_str());
exit(push.exit_code + pull.exit_code);
for (auto const& result : results) {
EXPECT_TRUE(Succeeded(result, transport));
}
}
TEST(PushPull, SingleMsg_MultiThreaded_ipc_zeromq)
{
EXPECT_EXIT(RunPushPull("zeromq", ""), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
RunPushPull("zeromq", "");
}
TEST(PushPull, SingleMsg_MultiThreaded_ipc_shmem)
{
EXPECT_EXIT(RunPushPull("shmem", ""), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
RunPushPull("shmem", "");
}
TEST(PushPull, SingleMsg_MultiThreaded_ipc_shmem_expanded_metadata)
{
EXPECT_EXIT(RunPushPull("shmem", " --shm-metadata-msg-size 2048"), ::testing::ExitedWithCode(0), "PUSH-PULL test successfull");
RunPushPull("shmem", "--shm-metadata-msg-size 2048");
}
} // namespace