diff --git a/test/unitTest/connectionManager/connectionManager.cpp b/test/unitTest/connectionManager/connectionManager.cpp index a8d1983d0905cdc870adc1e30c0c8b6c086dd37b..0299d84e0c57a343e774a377851d67942dfc3683 100644 --- a/test/unitTest/connectionManager/connectionManager.cpp +++ b/test/unitTest/connectionManager/connectionManager.cpp @@ -1081,7 +1081,20 @@ ConnectionManagerTest::testCanSendBeacon() // connectDevice is full async, so isConnecting will be true after a few ms. CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&] { return aliceSocket && bobSocket; })); CPPUNIT_ASSERT(aliceSocket->canSendBeacon()); - CPPUNIT_ASSERT(bobSocket->canSendBeacon()); + + // Because onConnectionReady is true before version is sent, we can wait a bit + // before canSendBeacon is true. + auto start = std::chrono::steady_clock::now(); + auto aliceCanSendBeacon = false; + auto bobCanSendBeacon = false; + do { + aliceCanSendBeacon = aliceSocket->canSendBeacon(); + bobCanSendBeacon = bobSocket->canSendBeacon(); + if (!bobCanSendBeacon || !aliceCanSendBeacon) + std::this_thread::sleep_for(1s); + } while (not bobCanSendBeacon and not aliceCanSendBeacon and std::chrono::steady_clock::now() - start < 5s); + + CPPUNIT_ASSERT(bobCanSendBeacon && aliceCanSendBeacon); } void