Skip to content

Make the muted loop-not-running test wait for the reschedule - #2592

Open
ps2 wants to merge 1 commit into
devfrom
test/wait-for-muted-loop-not-running
Open

ps2 wants to merge 1 commit into
devfrom
test/wait-for-muted-loop-not-running

Conversation

@ps2

@ps2 ps2 commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

testRescheduleMutedLoopNotLoopingAlerts fails now and then (XCTAssertNil on the time-sensitive notification's sound), usually on the first run after the simulator has been idle. Marion hit it while testing #2588.

Cause

Changing the muter reschedules the loop-not-running notifications from ExtensionDataManager.lastLoopCompleted, shared app-group data that the host app refreshes 0.5 s after launch. On the first run after an idle period, that value is more than 20 minutes old, so the muted reschedule schedules nothing, and the unmuted notifications from loopDidComplete stay pending with sound. Earlier runs also save a 4-hour mute in UserDefaults, which mutes the first scheduling pass and hides the problem until it expires. The test also read the pending notifications once, possibly before the muted versions had replaced the others.

Change

  • The test sets the extension context's last loop date to the date it passes to loopDidComplete.
  • It reads the pending notifications until the time-sensitive one has no sound, for up to 5 s, then asserts as before.

Testing

  • AlertManagerTests: 21 pass on an iPhone 17 Pro simulator.
  • I could not reproduce the original failure here. On a simulator without notification permission the pending list is empty, so the test passes without checking anything; on a cloned simulator with permission, the notification center didn't respond at all. The cause above comes from reading the code.

testRescheduleMutedLoopNotLoopingAlerts failed now and then on the first
run after a simulator had been idle. Changing the muter reschedules the
loop-not-running notifications from ExtensionDataManager.lastLoopCompleted,
which the host app refreshes only after launch; a value more than 20
minutes old schedules nothing, leaving the unmuted notifications from
loopDidComplete in place. Earlier runs also leave a 4-hour mute in
UserDefaults, which hides the problem until it expires.

The test now sets the last loop date it reschedules from, and reads the
pending notifications until the muted versions replace the others, for
up to 5 seconds, instead of reading them once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants