diff --git a/tests/bridge_test.cpp b/tests/bridge_test.cpp index bab79f2..9bed7be 100644 --- a/tests/bridge_test.cpp +++ b/tests/bridge_test.cpp @@ -79,37 +79,53 @@ private slots: const auto before = bridge.history().size(); QTest::qWait(1100); QCOMPARE(bridge.history().size(), before); - QSignalSpy samples(&bridge, &Bridge::snapshotChanged); + // Capture at emission: QTRY processes events, so another timer sample can + // replace bridge.snapshot() before the waiting assertion runs. + QVariantList samples; + QList historySizes; + QObject sampleObserver; // Disconnect before the captured lists are destroyed. + connect(&bridge, &Bridge::snapshotChanged, &sampleObserver, [&] { + samples.append(bridge.snapshot()); + historySizes.append(bridge.history().size()); + }); bridge.setPaused(false); QTRY_VERIFY_WITH_TIMEOUT(samples.count() > 0, 8000); - QVERIFY(!bridge.snapshot() + QVERIFY(!samples.first().toMap() .value("system") .toMap() .value("continuous") .toBool()); - QCOMPARE(bridge.history().size(), 1); + QCOMPARE(historySizes.first(), 1); bridge.active(false); QTest::qWait(600); samples.clear(); + historySizes.clear(); bridge.active(true); QTRY_VERIFY_WITH_TIMEOUT(samples.count() > 0, 8000); - QVERIFY(!bridge.snapshot() + QVERIFY(!samples.first().toMap() .value("system") .toMap() .value("continuous") .toBool()); QTRY_VERIFY_WITH_TIMEOUT(!bridge.busy(), 8000); samples.clear(); + historySizes.clear(); bridge.refresh(); QVERIFY(bridge.busy()); bridge.setPaused(true); bridge.setPaused(false); QTRY_VERIFY_WITH_TIMEOUT(samples.count() > 0, 8000); - QVERIFY(!bridge.snapshot() + QVERIFY(!samples.first().toMap() .value("system") .toMap() .value("continuous") .toBool()); + QCOMPARE(historySizes.first(), 1); + // Keep automatic refresh enabled. The baseline must be followed by a + // continuous sample; inspecting only the latest snapshot misses this order. + QTRY_VERIFY_WITH_TIMEOUT(samples.count() >= 2, 8000); + QVERIFY(samples.at(1).toMap().value("system").toMap() + .value("continuous").toBool()); QTRY_VERIFY_WITH_TIMEOUT(!bridge.busy(), 8000); QVERIFY(bridge.prepareManagement({{"category", "startup"}}).isEmpty()); QVERIFY(