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;