From 63359a691a2deb6dfe9102d8f6a1997420d1c27d Mon Sep 17 00:00:00 2001
From: Christoph Kampmeyer <christoph.kampmeyer@desy.de>
Date: Mon, 6 Jul 2020 10:57:20 +0200
Subject: [PATCH] testProcessVariableRecovery: Sync to start of mainLoop

---
 .../testProcessVariableRecovery.cc                | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/tests/executables_src/testProcessVariableRecovery.cc b/tests/executables_src/testProcessVariableRecovery.cc
index 5ed0b329..98d069ff 100644
--- a/tests/executables_src/testProcessVariableRecovery.cc
+++ b/tests/executables_src/testProcessVariableRecovery.cc
@@ -14,6 +14,7 @@
 #include <ChimeraTK/Device.h>
 #include <stdlib.h>
 #include <regex>
+#include <boost/thread/barrier.hpp>
 
 
 using namespace boost::unit_test_framework;
@@ -26,13 +27,24 @@ static constexpr char deviceCDD[] = "(ExceptionDummy?map=test5.map)";
  * application first sees the exception.
  */
 struct TestModule : public ctk::ApplicationModule {
-  using ctk::ApplicationModule::ApplicationModule;
+  TestModule(EntityOwner* owner, const std::string& name, const std::string& description,
+      ctk::HierarchyModifier hierarchyModifier = ctk::HierarchyModifier::none,
+      const std::unordered_set<std::string>& tags = {})
+  : ApplicationModule(owner, name, description, hierarchyModifier, tags), mainLoopStarted(2) {}
 
   ctk::ScalarPushInput<int32_t> trigger{this, "trigger", "", "This is my trigger."};
   ctk::ScalarOutput<int32_t> scalarOutput{this, "TO_DEV_SCALAR1", "", "Here I write a scalar"};
   ctk::ArrayOutput<int32_t> arrayOutput{this, "TO_DEV_ARRAY1", "", 4, "Here I write an array"};
 
+  // We do not use testable mode for this test, so we need this barrier to synchronise to the beginning of the
+  // mainLoop(). This is required to make sure the initial value propagation is done.
+  // execute this right after the Application::run():
+  //   app.testModule.mainLoopStarted.wait(); // make sure the module's mainLoop() is entered
+  boost::barrier mainLoopStarted;
+
   void mainLoop() override {
+    mainLoopStarted.wait();
+
     while(true) {
       trigger.read();
       scalarOutput = int32_t(trigger);
@@ -149,6 +161,7 @@ BOOST_AUTO_TEST_CASE(testProcessVariableRecovery) {
   test.writeScalar("/TEST/trigger", 0);
 
   app.run();
+  app.module.mainLoopStarted.wait();
 
   ctk::Device dummy;
   dummy.open(deviceCDD);
-- 
GitLab