Skip to content

[FSSDK-13238] test: fix flaky LruCache, EventDispatcher, and concurrent logging tests - #662

Merged
Muzahidul Islam (muzahidul-opti) merged 2 commits into
masterfrom
muzahid/fix-lrucache-threadsafe-test
Oct 7, 2026
Merged

Muzahidul Islam (muzahidul-opti) merged 2 commits into
masterfrom
muzahid/fix-lrucache-threadsafe-test

Conversation

@muzahidul-opti

@muzahidul-opti Muzahidul Islam (muzahidul-opti) commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes four flaky unit tests that failed by chance on CI. Each was turning master or PR runs red. Test code only, no SDK changes.

Test Why it failed Fix
LruCacheTests.testThreadSafe 99 other threads can evict key i from the 3-slot cache between save and lookup. That's correct LRU behavior, but the test expected the value to still be there A lookup may come back empty, but a value that's there must be correct. Also checks the cache ends with ≤ 3 entries
EventDispatcherTests.testDefaultDispatcher Posted to the live event endpoint. A slow or flaky runner network meant the flush didn't finish within 10 s Mock the URL session (MockUrlSession). The real send → remove-from-queue path still runs
EventDispatcherTests.testDispatcherCustomUrl Changed the static EventForDispatch.eventEndpoint and never restored it. Since #661, the built-in retry re-runs failed tests in the same process, so a retry of this test could never pass defer restores the default endpoint
LoggerTests_MultiClients.testConcurrentLogging (+ _MultipleLoggerInstances) 8,000 os_log calls had to finish within 10 s. Busy runners missed it: "Concurrent tasks timed out" 60 s limit. The test checks for crashes, not speed
LruCache race:
queue order:  T1 save(42) │ T7 save(3) │ T9 save(810) │ T4 save(77) │ T1 lookup(42)
cache (3):    [42]          [42,3]       [42,3,810]     [3,810,77]     → 42 evicted → nil ❌

Evidence

Failures on CI:

  • testThreadSafe: Apple TV failed on master, run 37580705312
  • testDefaultDispatcher ×3 and testConcurrentLogging ×2: iPhone Air failed on the first CI run of this PR

Local runs (-run-tests-until-failure):

  • Before:

    • testThreadSafe failed on iteration 1 of 50 on tvOS: ("nil") is not equal to ("Optional(1820)")
    • testDispatcherCustomUrl failed on iteration 2: the endpoint leaked from iteration 1
  • After:

    Test class tvOS iOS (iPhone 17)
    LruCacheTests 50× all passed 50× all passed
    EventDispatcherTests 20× all passed (200/200) —
    EventDispatcherTests + LoggerTests_MultiClients — 20× all passed (240/240)

A slow CI runner can't be reproduced locally, so the logging timeout is only proven by CI.

Merge Danger

Door: two-way (test-only)
Blast Radius: 3 test files in the Common and MultiClients test targets. No SDK code changes.

Issues

  • FSSDK-13238

🤖 Generated with Claude Code

With 100 threads writing into a size-3 cache, another thread can evict
key i between save and lookup, so asserting the lookup returns v fails
by chance. Assert that a hit holds the right value and that the cache
ends within its size limit instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coveralls

Coveralls (coveralls) commented Oct 7, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 93.929%. remained the same — muzahid/fix-lrucache-threadsafe-test into master

@datadog-optimizely-experimentation

This comment has been minimized.

- testDefaultDispatcher: mock the URL session instead of posting to the
  live event endpoint, which timed out on CI runners
- testDispatcherCustomUrl: restore the static eventEndpoint so retries
  and later tests see the default
- testConcurrentLogging(_MultipleLoggerInstances): allow 60s instead of
  10s for 8000 os_log calls; the test checks for crashes, not speed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@muzahidul-opti Muzahidul Islam (muzahidul-opti) changed the title [FSSDK-13238] test: fix flaky LruCacheTests.testThreadSafe [FSSDK-13238] test: fix flaky LruCache, EventDispatcher, and concurrent logging tests Oct 7, 2026
@muzahidul-opti
Muzahidul Islam (muzahidul-opti) merged commit 2d6d0d6 into master Oct 7, 2026
13 of 14 checks passed
@muzahidul-opti
Muzahidul Islam (muzahidul-opti) deleted the muzahid/fix-lrucache-threadsafe-test branch October 7, 2026 11:32
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