Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions Tests/Segment-Tests/Storage_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class StorageTests: XCTestCase {
let analytics = Analytics(configuration: Configuration(writeKey: uniqueWriteKey())
.storageMode(.memory(10))
.trackApplicationLifecycleEvents(false)
// a slow real request keeps analytics alive past waitUntilFinished's timeout.
.httpSession(RestrictedHTTPSession())
)

analytics.waitUntilStarted()
Expand Down
22 changes: 13 additions & 9 deletions Tests/Segment-Tests/StressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
import XCTest
@testable import Segment

// the network is faked, but on a busy runner an upload can still sit long enough to hit URLSession's
// timeout. that batch stays in storage and goes out on a later flush, so it isn't a storage failure.
private func failOnStorageError(_ error: Error) {
if case AnalyticsError.networkUnknown(_, let underlying) = error, (underlying as? URLError)?.code == .timedOut {
return
}
XCTFail("Storage Error: \(error)")
}

class StressTests: XCTestCase {

override func setUpWithError() throws {
Expand All @@ -28,9 +37,7 @@ class StressTests: XCTestCase {
guard URLProtocol.registerClass(BlockNetworkCalls.self) else { XCTFail(); return }

let analytics = Analytics(configuration: Configuration(writeKey: uniqueWriteKey())
.errorHandler({ error in
XCTFail("Storage Error: \(error)")
})
.errorHandler(failOnStorageError)
.httpSession(RestrictedHTTPSession())
)
analytics.purgeStorage()
Expand Down Expand Up @@ -111,9 +118,7 @@ class StressTests: XCTestCase {
guard URLProtocol.registerClass(BlockNetworkCalls.self) else { XCTFail(); return }

let analytics = Analytics(configuration: Configuration(writeKey: uniqueWriteKey())
.errorHandler({ error in
XCTFail("Storage Error: \(error)")
})
.errorHandler(failOnStorageError)
.httpSession(RestrictedHTTPSession())
)
analytics.purgeStorage()
Expand Down Expand Up @@ -243,9 +248,8 @@ class StressTests: XCTestCase {
let analytics = Analytics(configuration:
Configuration(writeKey: "stressTestMemory")
.storageMode(.memory(30_000))
.errorHandler({ error in
XCTFail("Storage Error: \(error)")
}))
.errorHandler(failOnStorageError)
.httpSession(RestrictedHTTPSession()))
analytics.storage.hardReset(doYouKnowHowToUseThis: true)

waitUntilStarted(analytics: analytics)
Expand Down
Loading