Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Tests/OptimizelyTests-Common/EventDispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions Tests/OptimizelyTests-Common/LruCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,19 @@ class LruCacheTests: XCTestCase {
let numThreads = 100
let numIterationPerThread = 1000

let cache = LruCache<Int, Int>(size: 3, timeoutInSecs: 1)
let cache = LruCache<Int, Int>(size: 3, timeoutInSecs: 60)
let result = OTUtils.runConcurrent(count: numThreads, timeoutInSecs: 10) { idx in
for i in 0..<numIterationPerThread {
let v = i * 10
cache.save(key: i, value: v)
XCTAssertEqual(cache.lookup(key: i), v)
// other threads may evict key i before this lookup; a hit must still hold the right value
if let found = cache.lookup(key: i) {
XCTAssertEqual(found, v)
}
}
}
XCTAssertTrue(result, "Concurrent tasks timed out")
XCTAssertLessThanOrEqual(cache.queue.sync { cache.map.count }, 3)
}

func testRemoveIsThreadSafe() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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..<numEventsPerThread {
logger.e("error-level: \(item)-\(i)")
logger.w("warning-level: \(item)-\(i)")
Expand All @@ -50,7 +51,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
let logger = DefaultLogger()

for i in 0..<numEventsPerThread {
Expand Down
Loading