Skip to content

test(ios): de-flake shutdown-IPC assertions via deterministic wait#147

Merged
gmaclennan merged 1 commit into
mainfrom
fix/mock-backend-shutdown-race
Jun 23, 2026
Merged

test(ios): de-flake shutdown-IPC assertions via deterministic wait#147
gmaclennan merged 1 commit into
mainfrom
fix/mock-backend-shutdown-race

Conversation

@gmaclennan

Copy link
Copy Markdown
Member

Problem

Swift Package Tests (macOS) flaked on testStopSendsShutdownMessageOverIPC (and the same pattern in testGracefulShutdownFlow) — e.g. run 28023239180. Surfaced while CI ran it against PR #107, but it is independent of that PR: the failing run's Swift sources were byte-identical to a parent commit that passed, so it's a pre-existing test race, not a regression.

Root cause

Both tests asserted backend.receivedShutdown immediately after stop() returned. MockBackend sets that flag on a background read loop, so the assertion raced the loop — and read the plain Bool with no cross-thread memory barrier. Waiting for the STOPPING transition doesn't guarantee the backend has read the shutdown frame yet.

Fix

MockBackend gains a shutdownObserved semaphore (signaled when the shutdown frame is read) and a waitForShutdown(timeout:) method — mirroring the existing handshakeComplete / waitForHandshake idiom. Both tests now waitForShutdown(...) before signalling node exit (the frame is sent by stop() before it blocks, so the socket is still alive), instead of peeking the flag. The semaphore also provides the happens-before the bare bool read lacked.

Verification

  • Full swift test suite green.
  • The two affected tests passed 20/20 under a local stress loop (Swift 6.3.2 / Xcode 26.5).

🤖 Generated with Claude Code

testStopSendsShutdownMessageOverIPC and testGracefulShutdownFlow asserted
backend.receivedShutdown immediately after stop(), racing MockBackend's
background read loop — and reading the bool with no cross-thread memory
barrier. CI hit this intermittently (e.g. run 28023239180).

Add a shutdownObserved semaphore signaled when the shutdown frame is read,
plus waitForShutdown(timeout:), mirroring the existing handshakeComplete /
waitForHandshake idiom. Both tests now await it (before signalling node
exit, while the socket is still alive) instead of peeking the flag.

Verified: full `swift test` suite green + the two tests passed 20/20 under
a stress loop locally (Swift 6.3.2 / Xcode 26.5).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the maintenance Refactor / test / chore / ci / build (changelog) label Jun 23, 2026
@gmaclennan gmaclennan added this pull request to the merge queue Jun 23, 2026
Merged via the queue into main with commit f2b28bd Jun 23, 2026
21 checks passed
@gmaclennan gmaclennan deleted the fix/mock-backend-shutdown-race branch June 23, 2026 13:57
gmaclennan added a commit that referenced this pull request Jun 23, 2026
## Optic Release Automation

This **draft** PR is opened by Github action
[optic-release-automation-action](https://github.com/nearform-actions/optic-release-automation-action).

A new **draft** GitHub release
[v1.0.0-pre.4](https://github.com/digidem/comapeo-core-react-native/releases/tag/untagged-884b8ff33e96eff7e06b)
has been created.

Release author: @gmaclennan

#### If you want to go ahead with the release, please merge this PR.
When you merge:

- The GitHub release will be published

- The npm package with tag pre will be published according to the
publishing rules you have configured



- No major or minor tags will be updated as configured


#### If you close the PR

- The new draft release will be deleted and nothing will change

<!-- Release notes generated using configuration in .github/release.yml
at 353e6e9 -->

## What's Changed
### 🚀 Features
* feat(android): migrate rootkey from expo-secure-store on first boot by
@gmaclennan in
#107
### 🐛 Bug Fixes
* fix(backend): apply defaultOnlineStyleUrl to the standalone map server
by @gmaclennan in
#148
### 🏗️ Maintenance
* test(ios): de-flake shutdown-IPC assertions via deterministic wait by
@gmaclennan in
#147


**Full Changelog**:
v1.0.0-pre.3...v1.0.0-pre.4

<!--

<release-meta>{"id":343614988,"version":"v1.0.0-pre.4","npmTag":"pre","opticUrl":"https://optic-zf3votdk5a-ew.a.run.app/api/generate/"}</release-meta>
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Refactor / test / chore / ci / build (changelog)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant