From be857dec8e9ccb23c9ebbfd2dea97c1aa7794588 Mon Sep 17 00:00:00 2001 From: Jozef Koval Date: Wed, 30 Sep 2026 16:58:35 +0200 Subject: [PATCH] Inject the engine clock in the timeout-restore BLE test With an unlosable responder deadline, the quarantine in timeoutRestoredSessionDefersQueueDrainUntilConvergence lasts until the test fires the timeout. On a slow runner the real 5 s capability-proof watchdog armed at the setup authentication can then expire inside the quarantine. Its drain takes the parked typed payload, cannot encrypt under a quarantined session and drops it, so the final drain yields two packets instead of three. That failed this branch's first CI run at BLEServiceCoreTests.swift:1022 (`drained`). The test now uses BLEEngineManualScheduler, the pattern this file already uses for engine deadlines, so the watchdog expires only where the test fires it. Verified: holding the quarantine open for 5.5 s reproduces the CI failure without the injected clock and passes with it, and the test still fails when the product ignores the deferral flag. --- bitchatTests/BLEServiceCoreTests.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bitchatTests/BLEServiceCoreTests.swift b/bitchatTests/BLEServiceCoreTests.swift index be01e685..c9cad525 100644 --- a/bitchatTests/BLEServiceCoreTests.swift +++ b/bitchatTests/BLEServiceCoreTests.swift @@ -858,8 +858,16 @@ struct BLEServiceCoreTests { // The responder deadline also arms during the setup handshake below, // where a stalled runner would let a short one tear the half-open // responder down. It is unlosable here and fired explicitly. + // + // The engine clock is injected for the same reason. With an unlosable + // deadline the quarantine lasts until this test fires it, and on a + // slow runner the real 5s capability-proof watchdog armed at the + // setup authentication can expire inside it. Its drain cannot + // encrypt under a quarantined session and drops the parked payload, + // so the final drain comes up one packet short. let ble = makeService( - noiseResponderHandshakeTimeout: TestConstants.unlosableInterval + noiseResponderHandshakeTimeout: TestConstants.unlosableInterval, + engineScheduler: BLEEngineManualScheduler() ) let alice = NoiseEncryptionService(keychain: MockKeychain()) let mallory = NoiseEncryptionService(keychain: MockKeychain()) @@ -959,8 +967,8 @@ struct BLEServiceCoreTests { #expect(outbound.count(ofType: .noiseEncrypted) == 0) // The capability-proof watchdog armed at the original authentication - // is still live and can genuinely reach its real 5s deadline here on - // a stalled CI runner. Fire it deterministically: its drain must + // is still live, and on the injected clock it expires only when + // fired. Fire it here, while the restore is current: its drain must // respect the deferred-until-convergence state instead of encrypting // the parked queues under the restored keys (the exact silent loss // the defer path exists to prevent). The retry below then still