tests: Attempt to fix race in rauc test

CI tests with asan/ubsan sometimes fail in system_rauc test. [1]

The test log looks like this:

```
 /home/ci/src/cesnet-gerrit-public/CzechLight/velia/tests/system_rauc.cpp:8:
 TEST CASE:  Fetch RAUC data over DBus
   Installation OK

 /home/ci/src/cesnet-gerrit-public/CzechLight/velia/tests/system_rauc.cpp:142: FATAL ERROR: REQUIRE( rauc->operation() == "installing" ) is NOT correct!
   values: REQUIRE( idle == installing )

 (...)
```

By looking at the code, it seems that the contents of the REQUIRE macro
 REQUIRE(rauc->operation() == "installing");
is executed before the RAUC installation actually starts (it is executed
from another thread) and therefore before it sets current DBus property
"Operation" to value "installing".
Let's try to fix that by waiting for the installation to actually start.

Jan: also extend the wait in case of a simulated failing installation so
that the test suite has a chance to react to this event.

[1] https://object-store.cloud.muni.cz/swift/v1/ci-logs-public/70/5270/2/check/f34-clang-asan-ubsan/4467b92/job-output.txt

Change-Id: I8e6e217660f3b87045a5538949a84139573a005a
Signed-off-by: Jan Kundrát <jan.kundrat@cesnet.cz>
diff --git a/tests/dbus-helpers/dbus_rauc_server.cpp b/tests/dbus-helpers/dbus_rauc_server.cpp
index 94930c3..865b681 100644
--- a/tests/dbus-helpers/dbus_rauc_server.cpp
+++ b/tests/dbus-helpers/dbus_rauc_server.cpp
@@ -169,7 +169,7 @@
     m_manager->emitPropertiesChangedSignal(interfaceManager, {"LastError", "Progress"});
 
     PROGRESS(0, "Determining slot states", 2);
-    WAIT(25ms);
+    WAIT(500ms);
     PROGRESS(20, "Determining slot states done.", 2);
     PROGRESS(20, "Checking bundle", 2);
     PROGRESS(40, "Checking bundle failed.", 2);
diff --git a/tests/system_rauc.cpp b/tests/system_rauc.cpp
index 3a20869..2656f8d 100644
--- a/tests/system_rauc.cpp
+++ b/tests/system_rauc.cpp
@@ -5,10 +5,22 @@
 #include "system/RAUC.h"
 #include "test_log_setup.h"
 
+using namespace std::literals::chrono_literals;
+
+/** @brief waits until expectation is saturated, but 150ms at most */
+void waitForSaturation(const std::unique_ptr<trompeloeil::expectation>& exp)
+{
+    static const auto WAIT_FOR_INSTALLATION_START_STEP = 5ms;
+    static const auto WAIT_FOR_INSTALLATION_START_MAX_STEPS = 30;
+
+    for (auto i = 0; i < WAIT_FOR_INSTALLATION_START_MAX_STEPS && !exp->is_saturated(); i++) {
+        std::this_thread::sleep_for(WAIT_FOR_INSTALLATION_START_STEP);
+    }
+    REQUIRE(exp->is_saturated());
+}
+
 TEST_CASE("Fetch RAUC data over DBus")
 {
-    using namespace std::literals::chrono_literals;
-
     TEST_INIT_LOGS;
     trompeloeil::sequence seq1;
 
@@ -112,7 +124,7 @@
     SECTION("Installation OK")
     {
         server.installBundleBehaviour(DBusRAUCServer::InstallBehaviour::OK); // Not cool but I don't feel like I should be creating some abstractions here in tests.
-        FAKE_RAUC_OPERATION("installing");
+        auto exp = NAMED_REQUIRE_CALL(fakeRaucInstallCb, operationCallback("installing")).IN_SEQUENCE(seq1);
         FAKE_RAUC_PROGRESS(0, "Installing");
         FAKE_RAUC_PROGRESS(0, "Determining slot states");
         FAKE_RAUC_PROGRESS(20, "Determining slot states done.");
@@ -139,6 +151,7 @@
         FAKE_RAUC_OPERATION("idle");
 
         rauc->install("/path/to/bundle");
+        waitForSaturation(exp); // wait until installation starts
         REQUIRE(rauc->operation() == "installing");
 
         SECTION("Invoking another operation before the installation ends")
@@ -154,7 +167,7 @@
     {
         server.installBundleBehaviour(DBusRAUCServer::InstallBehaviour::FAILURE);
 
-        FAKE_RAUC_OPERATION("installing");
+        auto exp = NAMED_REQUIRE_CALL(fakeRaucInstallCb, operationCallback("installing")).IN_SEQUENCE(seq1);
         FAKE_RAUC_PROGRESS(0, "Installing");
         FAKE_RAUC_PROGRESS(0, "Determining slot states");
         FAKE_RAUC_PROGRESS(20, "Determining slot states done.");
@@ -165,6 +178,7 @@
         FAKE_RAUC_OPERATION("idle");
 
         rauc->install("/path/to/bundle");
+        waitForSaturation(exp); // wait until installation starts
         REQUIRE(rauc->operation() == "installing");
         waitForCompletionAndBitMore(seq1);
         REQUIRE(rauc->lastError() == "Failed to download bundle https://10.88.3.11:8000/update.raucb: Transfer failed: error:1408F10B:SSL routines:ssl3_get_record:wrong version number");