Skip to content

Commit 9f56569

Browse files
browstudio
andauthored
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 <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
1 parent e8a8e4c commit 9f56569

2 files changed

Lines changed: 58 additions & 11 deletions

File tree

‎mobile/test/helpers/push_wake_fixture.dart‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,43 @@ class SlowShownMessageStore implements ShownMessageStore {
312312
}
313313
}
314314

315+
/// A store that holds the claim for [eventId] until [release] completes, then
316+
/// records it, as when storage stalls on one message past the wake's end.
317+
class HeldClaimShownMessageStore implements ShownMessageStore {
318+
HeldClaimShownMessageStore(this._inner, this.eventId, this.release);
319+
320+
final ShownMessageStore _inner;
321+
final String eventId;
322+
final Future<void> release;
323+
324+
/// Whether the resolver has started the held claim.
325+
bool entered = false;
326+
327+
/// Completes once the held claim has been recorded.
328+
Future<bool> get recorded => _recorded.future;
329+
final _recorded = Completer<bool>();
330+
331+
@override
332+
Future<DateTime?> newestShown(String community) =>
333+
_inner.newestShown(community);
334+
335+
@override
336+
Future<bool> claim(
337+
String community,
338+
String eventId,
339+
DateTime createdAt,
340+
) async {
341+
if (eventId != this.eventId) {
342+
return _inner.claim(community, eventId, createdAt);
343+
}
344+
entered = true;
345+
await release;
346+
final won = await _inner.claim(community, eventId, createdAt);
347+
_recorded.complete(won);
348+
return won;
349+
}
350+
}
351+
315352
/// A store whose claims for [community] fail after [succeed] of them, as when
316353
/// storage fills midway through a wake.
317354
class FailingShownMessageStore implements ShownMessageStore {

‎mobile/test/shared/push/push_wake_journey_test.dart‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,11 @@ void main() {
660660
expect(watch.elapsed, lessThan(const Duration(seconds: 2)));
661661
expect(result.failedCommunityIds, [relay.communityId]);
662662

663-
// Slow storage and a slow name lookup spend the budget too. Messages
664-
// not yet claimed stay unclaimed for the next wake, and those already
665-
// claimed are returned, not lost.
663+
// Storage that stalls on one claim past the budget doesn't hold the
664+
// wake. Messages not yet claimed stay unclaimed for the next wake. A
665+
// claim that only wins after the wake answered is recorded as shown but
666+
// never returned, so its community is reported incomplete and the
667+
// caller falls back.
666668
relay.silent = false;
667669
final friend = relay.person('Friend');
668670
final sent = [
@@ -677,21 +679,29 @@ void main() {
677679
metadata: Duration(seconds: 30),
678680
total: Duration(milliseconds: 700),
679681
);
680-
final slowStore = SlowShownMessageStore(
682+
// The oldest is claimed first, so the resolver always reaches it
683+
// before the deadline, however slow the runner.
684+
final heldId = sent.first;
685+
final release = Completer<void>();
686+
final heldStore = HeldClaimShownMessageStore(
681687
fixture.openStore(),
682-
const Duration(milliseconds: 100),
688+
heldId,
689+
release.future,
683690
);
684691
final stopped = Stopwatch()..start();
685-
final partial = await fixture.wake(store: slowStore, timeouts: tight);
692+
final partial = await fixture.wake(store: heldStore, timeouts: tight);
686693
expect(stopped.elapsed, lessThan(const Duration(seconds: 2)));
687-
expect(partial.incomplete, isTrue);
688-
expect(partial.notifications, isNotEmpty);
689-
expect(partial.notifications.length, lessThan(sent.length));
694+
expect(heldStore.entered, isTrue);
695+
release.complete();
696+
expect(await heldStore.recorded, isTrue);
697+
final partialIds = partial.notifications.map((n) => n.eventId).toList();
698+
expect(partialIds, isNot(contains(heldId)));
699+
expect(partial.failedCommunityIds, [relay.communityId]);
690700
final rest = await fixture.wake();
691701
expect(rest.incomplete, isFalse);
692702
expect(
693-
[...partial.notifications, ...rest.notifications].map((n) => n.eventId),
694-
unorderedEquals(sent),
703+
[...partialIds, ...rest.notifications.map((n) => n.eventId)]..sort(),
704+
[...sent.where((id) => id != heldId)]..sort(),
695705
);
696706

697707
relay.slowProfiles = true;

0 commit comments

Comments
 (0)