Repository navigation
test: ignore other SDK instances' batches in session event tests - #885
Merged
Merged
Conversation
MockPostHogServer can now record only batches carrying the test's project token.
2 of 4 tasks
dustinbyrne
approved these changes
Oct 1, 2026
This was referenced Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
"Clears $session_id after 30 mins of background inactivity" still fails intermittently on
test-ios-simulator, for example on #881 (run), after #878:#878 already sets
captureScreenViews = falsefor this suite, so those$screenevents can't come from the test's own SDK. They come from another test's SDK instance that is still running. Every SDK in the test process posts tolocalhost:9001, and OHHTTPStubs routes every/batchto whicheverMockPostHogServeris current. A foreign batch can then satisfy the test's batch expectation before its own events are sent. The test's existingserver.reset(batchCount: 1)("Clear any stale batch requests from previous tests' PostHogSDK instances") only clears batches that have already arrived. It doesn't help when one arrives during the test.MockPostHogServergets an optionalbatchProjectToken. When it's set,/batchrequests whoseapi_keydiffers aren't recorded. The body is buffered before parsing, because a stream-backed body can only be read once.getSut(). Each test already uses a freshUUID()token.This is test-only; SDK behavior and public API are unchanged.
💚 How did you test it?
Reproduced the failure deterministically by adding a second SDK with a different token that sends a
$screenwhile the test runs:-only-testing:PostHogTests/PostHogSessionManagerTest/PostHogSDKEvents(iOS 26 simulator)main+ snippetevents[0].event → "$screen", the same failure as CImake lint: no new violations.📝 Checklist
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Investigated and drafted with Claude Code (Claude Opus 5.5) while diagnosing the
test-ios-simulatorfailures blocking #872 and #881.api_keyat the mock fixes this whole class of failure without having to track down every leaked SDK. Closing every SDK in every suite would be a much larger change.🤖 Generated with Claude Code