From f43668baef8831423a7fd3176acf563772126f8b Mon Sep 17 00:00:00 2001 From: Muzahidul Islam Date: Wed, 7 Oct 2026 16:27:31 +0600 Subject: [PATCH 1/2] test: fix flaky LruCacheTests.testThreadSafe 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 --- Tests/OptimizelyTests-Common/LruCacheTests.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/OptimizelyTests-Common/LruCacheTests.swift b/Tests/OptimizelyTests-Common/LruCacheTests.swift index ede0d260..05419f89 100644 --- a/Tests/OptimizelyTests-Common/LruCacheTests.swift +++ b/Tests/OptimizelyTests-Common/LruCacheTests.swift @@ -153,15 +153,19 @@ class LruCacheTests: XCTestCase { let numThreads = 100 let numIterationPerThread = 1000 - let cache = LruCache(size: 3, timeoutInSecs: 1) + let cache = LruCache(size: 3, timeoutInSecs: 60) let result = OTUtils.runConcurrent(count: numThreads, timeoutInSecs: 10) { idx in for i in 0.. Date: Wed, 7 Oct 2026 17:05:07 +0600 Subject: [PATCH 2/2] test: fix flaky EventDispatcher and concurrent logging tests - 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 --- .../EventDispatcherTests.swift | 13 +++++++++++-- .../LoggerTests_MultiClients.swift | 6 ++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Tests/OptimizelyTests-Common/EventDispatcherTests.swift b/Tests/OptimizelyTests-Common/EventDispatcherTests.swift index f68ad16d..bb146e05 100644 --- a/Tests/OptimizelyTests-Common/EventDispatcherTests.swift +++ b/Tests/OptimizelyTests-Common/EventDispatcherTests.swift @@ -35,7 +35,14 @@ class EventDispatcherTests: XCTestCase { } func testDefaultDispatcher() { - eventDispatcher = DefaultEventDispatcher(timerInterval: 10) + // mock the network so the flush doesn't depend on reaching the live event endpoint + class MockSessionEventDispatcher: DefaultEventDispatcher { + override func getSession() -> URLSession { + return MockUrlSession() + } + } + + eventDispatcher = MockSessionEventDispatcher(timerInterval: 10) let pEventD: OPTEventDispatcher = eventDispatcher! pEventD.flushEvents() @@ -162,7 +169,9 @@ class EventDispatcherTests: XCTestCase { let originalUrl = "https://logx.optimizely.com/v1/events" let customUrl = "https://google.com" let overrideUrl = "https://apple.com" - + // eventEndpoint is static; restore it so later tests (and xcodebuild retries) see the default + defer { EventForDispatch.eventEndpoint = originalUrl } + // default end-point dispatcher.dispatchEvent(event: EventForDispatch(body: Data()), completionHandler: nil) diff --git a/Tests/OptimizelyTests-MultiClients/LoggerTests_MultiClients.swift b/Tests/OptimizelyTests-MultiClients/LoggerTests_MultiClients.swift index b0b7933d..f5397093 100644 --- a/Tests/OptimizelyTests-MultiClients/LoggerTests_MultiClients.swift +++ b/Tests/OptimizelyTests-MultiClients/LoggerTests_MultiClients.swift @@ -28,7 +28,8 @@ class LoggerTests_MultiClients: XCTestCase { let numThreads = 10 let numEventsPerThread = 100 - let result = OTUtils.runConcurrent(count: numThreads) { item in + // checks for crashes, not speed; 8000 os_log calls can take over the default 10s on a busy CI runner + let result = OTUtils.runConcurrent(count: numThreads, timeoutInSecs: 60) { item in for i in 0..