From 9f56569f6fd7f080ee9d4da3a5bff32375fc1719 Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Tue, 24 Nov 2026 18:03:25 -0800 Subject: [PATCH] test(mobile): hold a push wake claim past the deadline instead of timing it (#9919) ## Summary The push wake journey test checked the case where storage is still claiming messages when the wake's budget runs out by giving every claim a 100 ms delay and racing it against a 700 ms budget. On a loaded machine a claim could land just after the 250 ms claim grace, be recorded as shown, and never be returned, so the test's "partial plus rest is everything" check failed intermittently. The test now holds exactly one claim open until the wake has answered, then releases it, and checks: - the held message is not in the wake's notifications; - its community is reported as failed, so the wake is incomplete; - every other message is shown exactly once across this wake and the next. A new `HeldClaimShownMessageStore` test helper holds the claim. No production code changes. ## Validation Test-only change. The rewritten case passed 3 of 3 consecutive runs locally. --------- Signed-off-by: Tom Brow Co-authored-by: studio --- mobile/test/helpers/push_wake_fixture.dart | 37 +++++++++++++++++++ .../shared/push/push_wake_journey_test.dart | 32 ++++++++++------ 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/mobile/test/helpers/push_wake_fixture.dart b/mobile/test/helpers/push_wake_fixture.dart index 938d9f3b3e..bf614ef2e5 100644 --- a/mobile/test/helpers/push_wake_fixture.dart +++ b/mobile/test/helpers/push_wake_fixture.dart @@ -312,6 +312,43 @@ class SlowShownMessageStore implements ShownMessageStore { } } +/// A store that holds the claim for [eventId] until [release] completes, then +/// records it, as when storage stalls on one message past the wake's end. +class HeldClaimShownMessageStore implements ShownMessageStore { + HeldClaimShownMessageStore(this._inner, this.eventId, this.release); + + final ShownMessageStore _inner; + final String eventId; + final Future release; + + /// Whether the resolver has started the held claim. + bool entered = false; + + /// Completes once the held claim has been recorded. + Future get recorded => _recorded.future; + final _recorded = Completer(); + + @override + Future newestShown(String community) => + _inner.newestShown(community); + + @override + Future claim( + String community, + String eventId, + DateTime createdAt, + ) async { + if (eventId != this.eventId) { + return _inner.claim(community, eventId, createdAt); + } + entered = true; + await release; + final won = await _inner.claim(community, eventId, createdAt); + _recorded.complete(won); + return won; + } +} + /// A store whose claims for [community] fail after [succeed] of them, as when /// storage fills midway through a wake. class FailingShownMessageStore implements ShownMessageStore { diff --git a/mobile/test/shared/push/push_wake_journey_test.dart b/mobile/test/shared/push/push_wake_journey_test.dart index 23eef2e10d..666a0a0b62 100644 --- a/mobile/test/shared/push/push_wake_journey_test.dart +++ b/mobile/test/shared/push/push_wake_journey_test.dart @@ -660,9 +660,11 @@ void main() { expect(watch.elapsed, lessThan(const Duration(seconds: 2))); expect(result.failedCommunityIds, [relay.communityId]); - // Slow storage and a slow name lookup spend the budget too. Messages - // not yet claimed stay unclaimed for the next wake, and those already - // claimed are returned, not lost. + // Storage that stalls on one claim past the budget doesn't hold the + // wake. Messages not yet claimed stay unclaimed for the next wake. A + // claim that only wins after the wake answered is recorded as shown but + // never returned, so its community is reported incomplete and the + // caller falls back. relay.silent = false; final friend = relay.person('Friend'); final sent = [ @@ -677,21 +679,29 @@ void main() { metadata: Duration(seconds: 30), total: Duration(milliseconds: 700), ); - final slowStore = SlowShownMessageStore( + // The oldest is claimed first, so the resolver always reaches it + // before the deadline, however slow the runner. + final heldId = sent.first; + final release = Completer(); + final heldStore = HeldClaimShownMessageStore( fixture.openStore(), - const Duration(milliseconds: 100), + heldId, + release.future, ); final stopped = Stopwatch()..start(); - final partial = await fixture.wake(store: slowStore, timeouts: tight); + final partial = await fixture.wake(store: heldStore, timeouts: tight); expect(stopped.elapsed, lessThan(const Duration(seconds: 2))); - expect(partial.incomplete, isTrue); - expect(partial.notifications, isNotEmpty); - expect(partial.notifications.length, lessThan(sent.length)); + expect(heldStore.entered, isTrue); + release.complete(); + expect(await heldStore.recorded, isTrue); + final partialIds = partial.notifications.map((n) => n.eventId).toList(); + expect(partialIds, isNot(contains(heldId))); + expect(partial.failedCommunityIds, [relay.communityId]); final rest = await fixture.wake(); expect(rest.incomplete, isFalse); expect( - [...partial.notifications, ...rest.notifications].map((n) => n.eventId), - unorderedEquals(sent), + [...partialIds, ...rest.notifications.map((n) => n.eventId)]..sort(), + [...sent.where((id) => id != heldId)]..sort(), ); relay.slowProfiles = true;