diff --git a/test/device/_transitions.cxx b/test/device/_transitions.cxx index dcf320ed..29d4a7ad 100644 --- a/test/device/_transitions.cxx +++ b/test/device/_transitions.cxx @@ -6,13 +6,14 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ +#include "../helper/ControlDevice.h" + #include #include #include -#include -#include +#include namespace { @@ -23,23 +24,23 @@ using namespace fair::mq; TEST(Transitions, InvalidChangeState) { Device device; - thread t([&] { device.RunStateMachine(); }); + test::StateMachineThread t(device); ASSERT_FALSE(device.ChangeState(Transition::Connect)); ASSERT_TRUE(device.ChangeState(Transition::End)); - if (t.joinable()) { t.join(); } + t.Join(); } TEST(Transitions, InvalidChangeStateOrThrow) { Device device; - thread t([&] { device.RunStateMachine(); }); + test::StateMachineThread t(device); ASSERT_THROW(device.ChangeStateOrThrow(Transition::Connect), std::system_error); ASSERT_NO_THROW(device.ChangeStateOrThrow(Transition::End)); - if (t.joinable()) { t.join(); } + t.Join(); } } // namespace diff --git a/test/plugin_services/Fixture.h b/test/plugin_services/Fixture.h index 9aad35e9..bd65084b 100644 --- a/test/plugin_services/Fixture.h +++ b/test/plugin_services/Fixture.h @@ -18,7 +18,6 @@ #include #include -#include namespace fair::mq::test { @@ -28,9 +27,8 @@ struct PluginServices : ::testing::Test { : mConfig() , mDevice() , mServices(mConfig, mDevice) - , fRunStateMachineThread() + , fStateMachineThread(mDevice) { - fRunStateMachineThread = std::thread(&fair::mq::Device::RunStateMachine, &mDevice); mDevice.SetTransport("zeromq"); } @@ -39,15 +37,13 @@ struct PluginServices : ::testing::Test { if (mDevice.GetCurrentState() == State::Idle) { Control(mDevice, Cycle::ToDeviceReadyAndBack); } - if (fRunStateMachineThread.joinable()) { - fRunStateMachineThread.join(); - } + // fStateMachineThread drives the device to Exiting from any other state } ProgOptions mConfig; Device mDevice; mq::PluginServices mServices; - std::thread fRunStateMachineThread; + StateMachineThread fStateMachineThread; }; } // namespace fair::mq::test diff --git a/test/region/_region.cxx b/test/region/_region.cxx index e24a676e..0a2f3dc8 100644 --- a/test/region/_region.cxx +++ b/test/region/_region.cxx @@ -404,7 +404,7 @@ void RegionLockOrder(const string& _address) ASSERT_EQ(push.Send(msg), 100); } - thread creator([&] { + test::JoiningThread creator([&] { for (int i = 0; i < numIterations; ++i) { auto region = factory1->CreateUnmanagedRegion(10000, [](void*, size_t, void*) {}); } @@ -416,7 +416,7 @@ void RegionLockOrder(const string& _address) ASSERT_NE(msg->GetData(), nullptr); // opens the peer region in factory1 } - creator.join(); + creator.Join(); } TEST(RegionsSizeMismatch, shmem)