From 256a39db9b36dfa01b2383c6b4f01a2cc56c9e74 Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Thu, 12 Mar 2020 14:28:05 +0100
Subject: [PATCH] testPropagateDataFlag: adapted tests to changed behaviour
 (half way towards the new spec)

---
 src/Application.cc                            |  2 -
 .../testPropagateDataFaultFlag.cc             | 48 ++++++++++++++++---
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/src/Application.cc b/src/Application.cc
index db8971d4..e9b45b70 100644
--- a/src/Application.cc
+++ b/src/Application.cc
@@ -753,8 +753,6 @@ void Application::typedMakeConnection(VariableNetwork& network) {
           if(feedingDeviceImpl) {
             auto owningModule = consumer.getOwningModule(); // application module or variable group
             feedingDeviceImpl->setOwner(owningModule);
-            // The decorator comes up with data validity faulty, and we have to keep the counting consistent
-            owningModule->incrementDataFaultCounter();
           }
           connectionMade = true;
         }
diff --git a/tests/executables_src/testPropagateDataFaultFlag.cc b/tests/executables_src/testPropagateDataFaultFlag.cc
index 13b313a3..c85f6198 100644
--- a/tests/executables_src/testPropagateDataFaultFlag.cc
+++ b/tests/executables_src/testPropagateDataFaultFlag.cc
@@ -786,6 +786,23 @@ BOOST_AUTO_TEST_CASE(testDataFlowOnDeviceException) {
   // Now the device has to go into the error state
   CHECK_EQUAL_TIMEOUT((deviceStatus.readLatest(), deviceStatus), 1, 10000);
 
+  // The data is propagated once more to make sure the invaldi flag goes through (in this case it already was invalid, but
+  // cannot be nown by the code, see testDataValidPropagationOnException.
+  m1_result.read();
+  // FIXME: The correct behaviour according to the new spec is that the new value of threadedFanoutInput is already processed.
+  //BOOST_CHECK_EQUAL(m1_result, 1100);
+  BOOST_CHECK_EQUAL(m1_result, 1101);
+  BOOST_CHECK(m1_result.dataValidity() == ctk::DataValidity::faulty);
+  m2_result.read();
+  // FIXME: The correct behaviour according to the new spec is that the new value of threadedFanoutInput is already processed.
+  //BOOST_CHECK_EQUAL(m2_result, 1100);
+  BOOST_CHECK_EQUAL(m2_result, 1101);
+  BOOST_CHECK(m2_result.dataValidity() == ctk::DataValidity::faulty);
+
+  // Trigger the loop another time. Now the execution is blocked
+  threadedFanoutInput = 2;
+  threadedFanoutInput.write();
+
   // The result of m1 must not be written out again. We can't test this at this safely here.
   // Instead, we know that the next read after recovery will already contain the new data.
 
@@ -799,8 +816,26 @@ BOOST_AUTO_TEST_CASE(testDataFlowOnDeviceException) {
   // nothing else in the queue
   BOOST_CHECK(deviceStatus.readNonBlocking() == false);
 
-  m1_result.read(); // we know there must be exaclty one value being written. Wait for it.
+  /////////////////// FIXME: This is old behaviour and will go away with proper implementation of the spec//////////////////
+
+  // After recovering the old data has been written once, still with invalid because the fan input is still invalid
+  m1_result.read();
+  BOOST_CHECK_EQUAL(m1_result, 1101);
+  BOOST_CHECK(m1_result.dataValidity() == ctk::DataValidity::faulty);
+  m2_result.read();
+  BOOST_CHECK_EQUAL(m2_result, 1101);
+  BOOST_CHECK(m2_result.dataValidity() == ctk::DataValidity::faulty);
+
+  // Now the data for threadedFanoutInput = 0 is propagated. In the new spec this was already done above
+  m1_result.read();
   BOOST_CHECK_EQUAL(m1_result, 1200);
+  m2_result.read();
+  BOOST_CHECK_EQUAL(m2_result, 1200);
+
+  /////////////////// END OF FIXME: old behaviour ///////////////////////////////////////////////////
+
+  m1_result.read(); // we know there must be exaclty one value being written. Wait for it.
+  BOOST_CHECK_EQUAL(m1_result, 1202);
   // Data validity still faulty because the input from the fan is invalid
   BOOST_CHECK(m1_result.dataValidity() == ctk::DataValidity::faulty);
   // again, nothing else in the queue
@@ -808,22 +843,23 @@ BOOST_AUTO_TEST_CASE(testDataFlowOnDeviceException) {
 
   // same for m2
   m2_result.read();
-  BOOST_CHECK_EQUAL(m2_result, 1200);
+  BOOST_CHECK_EQUAL(m2_result, 1202);
   BOOST_CHECK(m2_result.dataValidity() == ctk::DataValidity::faulty);
   BOOST_CHECK(m2_result.readNonBlocking() == false);
 
   // ---------------------------------------------------------------------//
   // recovery: fanout input
+  threadedFanoutInput = 3;
   threadedFanoutInput.setDataValidity(ctk::DataValidity::ok);
   threadedFanoutInput.write();
 
   m1_result.read();
-  BOOST_CHECK_EQUAL(m1_result, 1200);
+  BOOST_CHECK_EQUAL(m1_result, 1203);
   BOOST_CHECK(m1_result.dataValidity() == ctk::DataValidity::ok);
   BOOST_CHECK(m1_result.readNonBlocking() == false);
 
   m2_result.read();
-  BOOST_CHECK_EQUAL(m2_result, 1200);
+  BOOST_CHECK_EQUAL(m2_result, 1203);
   BOOST_CHECK(m2_result.dataValidity() == ctk::DataValidity::ok);
   BOOST_CHECK(m1_result.readNonBlocking() == false);
 }
@@ -902,8 +938,8 @@ BOOST_AUTO_TEST_CASE(testDataValidPropagationOnException) {
 
   // Output should be rewritten and the data valditity should be propagated
   CHECK_EQUAL_TIMEOUT((deviceStatus.readLatest(), deviceStatus), 1, 10000);
-  CHECK_EQUAL_TIMEOUT(result.readNonBlocking(), true, 10000);
+  result.read();
+  BOOST_CHECK(result.readLatest() == false);
   BOOST_CHECK_EQUAL(result, 11);
-  std::cout << "Result is " << result << std::endl;
   BOOST_CHECK(result.dataValidity() == ctk::DataValidity::faulty);
 }
-- 
GitLab