mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-14 00:56:47 +00:00
Refactor multiple devices test for better readability
This commit is contained in:
parent
07f7142ae2
commit
1c7da53386
|
@ -19,83 +19,75 @@ namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace fair::mq;
|
||||||
|
|
||||||
void control(FairMQDevice& device)
|
void control(FairMQDevice& device)
|
||||||
{
|
{
|
||||||
device.ChangeState(fair::mq::Transition::InitDevice);
|
thread t([&] {
|
||||||
device.WaitForState(fair::mq::State::InitializingDevice);
|
device.ChangeState(Transition::InitDevice);
|
||||||
device.ChangeState(fair::mq::Transition::CompleteInit);
|
device.WaitForState(State::InitializingDevice);
|
||||||
device.WaitForState(fair::mq::State::Initialized);
|
device.ChangeState(Transition::CompleteInit);
|
||||||
device.ChangeState(fair::mq::Transition::Bind);
|
device.WaitForState(State::Initialized);
|
||||||
device.WaitForState(fair::mq::State::Bound);
|
device.ChangeState(Transition::Bind);
|
||||||
device.ChangeState(fair::mq::Transition::Connect);
|
device.WaitForState(State::Bound);
|
||||||
device.WaitForState(fair::mq::State::DeviceReady);
|
device.ChangeState(Transition::Connect);
|
||||||
device.ChangeState(fair::mq::Transition::InitTask);
|
device.WaitForState(State::DeviceReady);
|
||||||
device.WaitForState(fair::mq::State::Ready);
|
device.ChangeState(Transition::InitTask);
|
||||||
|
device.WaitForState(State::Ready);
|
||||||
|
|
||||||
device.ChangeState(fair::mq::Transition::Run);
|
device.ChangeState(Transition::Run);
|
||||||
device.WaitForState(fair::mq::State::Ready);
|
device.WaitForState(State::Ready);
|
||||||
|
|
||||||
device.ChangeState(fair::mq::Transition::ResetTask);
|
device.ChangeState(Transition::ResetTask);
|
||||||
device.WaitForState(fair::mq::State::DeviceReady);
|
device.WaitForState(State::DeviceReady);
|
||||||
device.ChangeState(fair::mq::Transition::ResetDevice);
|
device.ChangeState(Transition::ResetDevice);
|
||||||
device.WaitForState(fair::mq::State::Idle);
|
device.WaitForState(State::Idle);
|
||||||
|
|
||||||
device.ChangeState(fair::mq::Transition::End);
|
device.ChangeState(Transition::End);
|
||||||
|
});
|
||||||
|
|
||||||
|
device.RunStateMachine();
|
||||||
|
|
||||||
|
if (t.joinable()) {
|
||||||
|
t.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultipleDevices : public ::testing::Test {
|
class MultipleDevices : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
MultipleDevices()
|
MultipleDevices() {}
|
||||||
{}
|
|
||||||
|
|
||||||
bool TestFirst()
|
bool TestFirst()
|
||||||
{
|
{
|
||||||
fair::mq::test::Sender sender("data");
|
test::Sender sender("data");
|
||||||
|
|
||||||
sender.SetTransport("zeromq");
|
sender.SetTransport("zeromq");
|
||||||
|
|
||||||
FairMQChannel channel("push", "connect", "ipc://multiple-devices-test");
|
FairMQChannel channel("push", "connect", "ipc://multiple-devices-test");
|
||||||
channel.UpdateRateLogging(0);
|
channel.UpdateRateLogging(0);
|
||||||
sender.AddChannel("data", std::move(channel));
|
sender.AddChannel("data", std::move(channel));
|
||||||
|
|
||||||
thread t(control, std::ref(sender));
|
control(sender);
|
||||||
|
|
||||||
sender.RunStateMachine();
|
|
||||||
|
|
||||||
if (t.joinable()) {
|
|
||||||
t.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TestSecond()
|
bool TestSecond()
|
||||||
{
|
{
|
||||||
fair::mq::test::Receiver receiver("data");
|
test::Receiver receiver("data");
|
||||||
|
|
||||||
receiver.SetTransport("zeromq");
|
receiver.SetTransport("zeromq");
|
||||||
|
|
||||||
FairMQChannel channel("pull", "bind", "ipc://multiple-devices-test");
|
FairMQChannel channel("pull", "bind", "ipc://multiple-devices-test");
|
||||||
channel.UpdateRateLogging(0);
|
channel.UpdateRateLogging(0);
|
||||||
receiver.AddChannel("data", std::move(channel));
|
receiver.AddChannel("data", std::move(channel));
|
||||||
|
|
||||||
thread t(control, std::ref(receiver));
|
control(receiver);
|
||||||
|
|
||||||
receiver.RunStateMachine();
|
|
||||||
|
|
||||||
if (t.joinable()) {
|
|
||||||
t.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(MultipleDevices, TwoInSameProcess)
|
TEST_F(MultipleDevices, TwoInSameProcess)
|
||||||
{
|
{
|
||||||
std::future<bool> fut1 = std::async(std::launch::async, &MultipleDevices::TestFirst, this);
|
future<bool> fut1 = async(launch::async, &MultipleDevices::TestFirst, this);
|
||||||
std::future<bool> fut2 = std::async(std::launch::async, &MultipleDevices::TestSecond, this);
|
future<bool> fut2 = async(launch::async, &MultipleDevices::TestSecond, this);
|
||||||
|
|
||||||
bool first = fut1.get();
|
bool first = fut1.get();
|
||||||
bool second = fut2.get();
|
bool second = fut2.get();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user