-
Notifications
You must be signed in to change notification settings - Fork 33
[FSSDK-12240] fix: resolve test failures in EventDispatcherTests_Batch and add project documentation #621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
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
Added CLAUDE.md file to provide context and guidelines for development: - Project overview and structure - Getting started guide with platform support and installation - Coding standards and common patterns (protocol-oriented design, thread safety) - Complete development workflow from branch creation to PR - Testing guide with xcodebuild commands and best practices - Key API usage examples - Helpful commands for file searching, testing, and git operations The documentation is organized logically from introduction to reference material for better developer onboarding and contribution experience. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed test failures caused by non-deterministic JSON key ordering in Xcode 16.x by adding .sortedKeys to all JSONEncoder instances. Changes: - Sources/Utils/Utils.swift: Added .sortedKeys to static jsonEncoder used by UserAttribute.stringRepresentation generation - Tests/TestUtils/OTUtils.swift: Added .sortedKeys to isEqualWithEncodeThenDecode() and makeEventForDispatch() test utilities - Tests/OptimizelyTests-Common/DecisionServiceTests_Experiments.swift: Updated expected JSON error messages to use alphabetically sorted keys - Tests/OptimizelyTests-Common/OptimizelyUserContextTests_Decide_Reasons.swift: Updated expected JSON condition strings to use alphabetically sorted keys Root Cause: JSONEncoder produces non-deterministic key ordering without .sortedKeys, causing tests to fail on Xcode 16.x even though they passed on earlier versions. The UserAttribute model generates a stringRepresentation field using Utils.jsonEncoder during decode, which is then compared in equality checks. Without sorted keys, encode/decode cycles produce different stringRepresentation values. Fixes testEncodeJSON, DecisionServiceTests_Experiments, and OptimizelyUserContextTests_Decide_Reasons test failures. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixed three intermittently failing tests by replacing unreliable timing-based
synchronization with proper DispatchGroup waits and thread-safe option tracking.
Changes:
1. EventDispatcherRetryTests.swift:
- testRetry_AllAttemptsExhausted: Replaced asyncAfter with notify.wait()
- testRetry_NetworkReachabilityDown: Added notify.wait() for proper completion
2. OptimizelyUserContextTests_Decide_CMAB.swift:
- testDecideAsync_cmabCacheOptions: Fixed race condition by capturing options
in an array and validating after all async calls complete
- MockCmabService: Overrides async getDecision() to respect parent's locking,
uses separate optionsLock only for mock-specific tracking
The fixes eliminate race conditions by using the existing notify DispatchGroup
in DefaultEventDispatcher and ensuring thread-safe access to mock state.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added OTUtils.clearAllEventQueues() to setUp() to ensure each test starts with a clean queue. Previously only clearing in tearDown() meant that if a test failed or was interrupted, the next test would inherit leftover events from the queue. This fixes testRetry_AllAttemptsExhausted which was failing with 2 events in queue instead of 1 due to stale events from previous tests. Also fixed MockCmabService to override both sync and async getDecision() methods since DecisionService calls the sync version. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Added optimizely.decisionQueue.sync {} after wait(for:) to ensure all
queued async decision tasks finish executing before checking the mock's
capturedOptions array.
decideAsync dispatches work to a background decisionQueue. On CI, the
wait(for:) might complete (expectations fulfilled in callbacks) before
the actual getDecision() calls are tracked in the mock. The sync barrier
ensures all queued work completes.
Fixes intermittent CI failure: "0 is not equal to 3" in
testDecideAsync_cmabCacheOptions
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Consolidated duplicate sections to improve readability: - Moved all testing commands to dedicated 'Testing' section - Kept linting info only in 'Coding Standards' - Consolidated git commands in 'Helpful Commands' - Added cross-references in 'Making Changes' workflow - Removed repeated commands from multiple locations This reduces redundancy and makes the guide easier to maintain. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
Summary
This PR fixes failing test cases in
EventDispatcherTests_Batchand adds comprehensive project documentation to improve developer onboarding.Bug Fixes
Fixed
testFlushEventsWhenBatchFails: Test was timing out due to actual HTTP requests inTestEventDispatcher.sendEvent()TestEventDispatcherto simulate network completion immediately instead of making real network callsFixed
testInvalidEventInSecond: Test was failing due to non-deterministic JSON output.sortedKeystoJSONEncoderinArrayEventForDispatch+Extension.makeBatchEvent()Root Cause
The recent async retry strategy refactoring (commit 50c66b1) changed
DefaultEventDispatcherfrom synchronous to asynchronous retry logic. TheTestEventDispatcher.sendEvent()was callingsuper.sendEvent()which made actual HTTP requests to dummy URLs, causing timeouts and leaving events in the queue.Changes Made
Sources/Extensions/ArrayEventForDispatch+Extension.swift
.sortedKeysformatting toJSONEncoderinmakeBatchEvent()for deterministic JSON outputTests/OptimizelyTests-Batch-iOS/EventDispatcherTests_Batch.swift
TestEventDispatcher.sendEvent()to avoid real network callsCLAUDE.md (New)
Added comprehensive project documentation including:
Test Plan
testFlushEventsWhenBatchFailsnow passes in 0.018 seconds (previously timed out)testInvalidEventInSecondnow passes with deterministic JSON comparisonIssues