FairMQ/test/plugin_services/Fixture.h
Alexey Rybalchenko fc94342db8 Update state machine
- Split INITIALIZING state into Init+Bind+Connect
 - Remove PAUSE state
 - Convert state/transitions to enum classes (CamelCase)
 - Transition to a state only once previous handler is complete
 - Add CompleteInit transition to notify Initializing state
   that config updates are complete
 - Deprecate WaitForEndOfState(transition) in favor of
   WaitForState(state)/WaitForNextState()
 - Update tests/plugins to new APIs
 - Deprecate CheckCurrentState() in favor of NewStatePending()
2019-02-25 12:19:50 +01:00

72 lines
2.2 KiB
C++

/********************************************************************************
* Copyright (C) 2017 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_FIXTURE
#define FAIR_MQ_TEST_FIXTURE
#include <gtest/gtest.h>
#include <fairmq/PluginServices.h>
#include <FairMQDevice.h>
#include <options/FairMQProgOptions.h>
#include <memory>
#include <thread>
namespace fair
{
namespace mq
{
namespace test
{
inline auto control(FairMQDevice& device) -> void
{
device.ChangeState(fair::mq::Transition::InitDevice);
device.WaitForState(fair::mq::State::InitializingDevice);
device.ChangeState(fair::mq::Transition::CompleteInit);
device.WaitForState(fair::mq::State::Initialized);
device.ChangeState(fair::mq::Transition::Bind);
device.WaitForState(fair::mq::State::Bound);
device.ChangeState(fair::mq::Transition::Connect);
device.WaitForState(fair::mq::State::DeviceReady);
device.ChangeState(fair::mq::Transition::ResetDevice);
device.WaitForState(fair::mq::State::Idle);
device.ChangeState(fair::mq::Transition::End);
}
struct PluginServices : ::testing::Test {
PluginServices()
: mConfig()
, mDevice()
, mServices(mConfig, mDevice)
, fRunStateMachineThread()
{
fRunStateMachineThread = std::thread(&FairMQDevice::RunStateMachine, &mDevice);
mDevice.SetTransport("zeromq");
}
~PluginServices()
{
if (mDevice.GetCurrentState() == fair::mq::State::Idle) control(mDevice);
if (fRunStateMachineThread.joinable()) {
fRunStateMachineThread.join();
}
}
FairMQProgOptions mConfig;
FairMQDevice mDevice;
fair::mq::PluginServices mServices;
std::thread fRunStateMachineThread;
};
} /* namespace test */
} /* namespace mq */
} /* namespace fair */
#endif /* FAIR_MQ_TEST_FIXTURE */