Skip to content

Conversation

@muzahidul-opti
Copy link
Contributor

@muzahidul-opti muzahidul-opti commented Jan 22, 2026

Summary

  • Fixed flaky testDecideAsync_cmabCacheOptions failing with "Expected 3 calls to getDecision"
  • Fixed EventDispatcherRetryTests timing issues with proper synchronization
  • Fixed JSON encoding non-determinism causing failures on Xcode 16.x
  • Improved test isolation by preventing cache and queue pollution

Test plan

  • All CMAB tests pass consistently (testDecideAsync_cmabCacheOptions, etc.)
  • All EventDispatcherRetryTests pass with proper DispatchGroup synchronization
  • JSON encoding tests pass on all Xcode versions with .sortedKeys
  • Full test suite passes both individually and when run together
  • CI passes without flaky test failures

Issues

@muzahidul-opti muzahidul-opti changed the title Fix flaky tests with proper synchronization [FSSDK-12240] fix flaky tests with proper synchronization Jan 22, 2026
muzahidul-opti and others added 3 commits January 22, 2026 20:41
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>
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>
Fixed multiple test failures and flaky tests across the test suite:

1. **CMAB Test Fixes** (OptimizelyUserContextTests_Decide_CMAB.swift):
   - Fixed testDecideAsync_cmabCacheOptions failing with "Expected 3 calls"
   - Root cause: CMAB cache persisting between tests causing cache hits
   - Solution: Reset cache in setUp/tearDown, use unique userId
   - Added thread-safe state tracking in MockCmabService
   - Added clarifying comments for variation IDs
   - Removed commented-out code

2. **Event Dispatcher Retry Tests** (EventDispatcherRetryTests.swift):
   - Fixed testRetry_AllAttemptsExhausted timing issues
   - Fixed testRetry_NetworkReachabilityDown synchronization
   - Replaced unreliable asyncAfter with notify.wait() for proper completion
   - Added setUp queue clearing to prevent test pollution

3. **JSON Encoding Determinism** (Utils.swift, OTUtils.swift):
   - Fixed testEncodeJSON failures on Xcode 16.x
   - Added .sortedKeys to JSONEncoder for deterministic key ordering
   - Updated expected JSON strings in DecisionServiceTests_Experiments
   - Updated expected JSON strings in OptimizelyUserContextTests_Decide_Reasons

4. **Event Dispatcher Batch Tests** (EventDispatcherTests_Batch.swift):
   - Fixed ArrayEventForDispatch extension edge cases
   - Improved batch processing test reliability

5. **CI Configuration** (swift.yml, unit_tests.yml):
   - Updated test runner configuration for better reliability

All tests now pass reliably both individually and in the full suite.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@muzahidul-opti muzahidul-opti requested a review from jaeopt January 22, 2026 16:38
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@muzahidul-opti muzahidul-opti merged commit ceea27e into master Jan 23, 2026
58 of 83 checks passed
@muzahidul-opti muzahidul-opti deleted the fix-flaky-tests branch January 23, 2026 16:24
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.

3 participants