7 #define BOOST_TEST_MODULE testZeroMQ
8 #include <doocs-server-test-helper/doocsServerTestHelper.h>
10 #include <ChimeraTK/Device.h>
11 #include <ChimeraTK/TransferGroup.h>
13 #include <boost/test/included/unit_test.hpp>
15 #include <doocs-server-test-helper/ThreadedDoocsServer.h>
16 #include <doocs/EqCall.h>
18 #include <ChimeraTK/UnifiedBackendTest.h>
20 using namespace boost::unit_test_framework;
28 : ThreadedDoocsServer(
"testZeroMQ.conf", boost::unit_test::framework::master_test_suite().argc,
29 boost::unit_test::framework::master_test_suite().argv,
eq_dummy::createServer()) {
31 DoocsServer1 =
"(doocs:doocs://localhost:" + rpcNo() +
"/F/D)";
32 DoocsServer2 =
"(doocs:doocs://localhost:" + rpcNo() +
"/F/D/MYDUMMY)";
36 doocs::EqData src, dst;
37 ea.adr(
"doocs://localhost:" + rpcNo() +
"/F/D/MYDUMMY/SOME_ZMQINT");
38 while(eq.get(&ea, &src, &dst)) usleep(100000);
41 static std::string DoocsServer1;
42 static std::string DoocsServer2;
53 ChimeraTK::Device device;
55 device.activateAsyncRead();
57 ScalarRegisterAccessor<int32_t> acc(
58 device.getScalarRegisterAccessor<int32_t>(
"MYDUMMY/SOME_ZMQINT", 0, {AccessMode::wait_for_new_data}));
60 BOOST_CHECK(acc.readNonBlocking() ==
false);
68 while(!acc.readNonBlocking() || ++ic < 10) {
69 DoocsServerTestHelper::runUpdate();
76 BOOST_CHECK(acc.readNonBlocking() ==
false);
79 DoocsServerTestHelper::doocsSet(
"//MYDUMMY/SOME_ZMQINT", 1);
80 DoocsServerTestHelper::runUpdate();
82 CHECK_TIMEOUT(acc.readNonBlocking() ==
true, 300000);
83 BOOST_CHECK_EQUAL(acc, 2);
84 BOOST_CHECK(acc.readNonBlocking() ==
false);
87 DoocsServerTestHelper::runUpdate();
88 DoocsServerTestHelper::runUpdate();
89 DoocsServerTestHelper::runUpdate();
92 BOOST_CHECK_EQUAL(acc, 3);
93 CHECK_TIMEOUT(acc.readNonBlocking() ==
true, 30000);
94 BOOST_CHECK_EQUAL(acc, 4);
96 BOOST_CHECK_EQUAL(acc, 5);
100 std::atomic<bool> readFinished(
false);
101 std::promise<void> prom;
102 std::future<void> fut = prom.get_future();
103 std::thread readAsync([&acc, &prom, &readFinished]() {
108 fut.wait_for(std::chrono::milliseconds(500));
109 BOOST_CHECK(readFinished ==
false);
110 DoocsServerTestHelper::runUpdate();
111 fut.wait_for(std::chrono::milliseconds(500));
112 BOOST_CHECK(readFinished ==
true);
118 std::atomic<bool> threadInterrupted(
false);
119 std::promise<void> prom;
120 std::future<void> fut = prom.get_future();
121 std::thread readAsync([&acc, &prom, &threadInterrupted]() {
125 catch(boost::thread_interrupted&) {
127 threadInterrupted =
true;
131 fut.wait_for(std::chrono::milliseconds(500));
132 BOOST_CHECK(threadInterrupted ==
false);
133 acc.getHighLevelImplElement()->interrupt();
134 fut.wait_for(std::chrono::milliseconds(500));
135 BOOST_CHECK(threadInterrupted ==
true);