test(swift-ios): make native CI fast and deterministic
Multi-environment fixtures were spending four seconds per failed fake WebSocket request, and Xcode spent another 600 seconds collecting diagnostics after simulator launch failures. Use explicit loader receipts, inject a short fixture-only connection deadline, run one test host, skip verbose failure diagnostics, and cap individual test execution time.
This commit is contained in:
3 files changed
+62
-34
No files matched your search
@@ -972,6 +972,7 @@ public actor EnvironmentRuntime {
|
||||
private let httpTransport: any HTTPTransport
|
||||
private let webSocketConnector: any WebSocketConnecting
|
||||
private let managedAuthorization: (any ManagedEnvironmentAuthorizing)?
|
||||
private let rpcConnectionWaitTimeout: Duration
|
||||
private var clients: [String: T3Client] = [:]
|
||||
|
||||
public init(
|
||||
@@ -979,13 +980,15 @@ public actor EnvironmentRuntime {
|
||||
credentialStore: any CredentialStore = KeychainCredentialStore(),
|
||||
httpTransport: any HTTPTransport = URLSessionHTTPTransport(),
|
||||
webSocketConnector: any WebSocketConnecting = URLSessionWebSocketConnector(),
|
||||
managedAuthorization: (any ManagedEnvironmentAuthorizing)? = nil
|
||||
managedAuthorization: (any ManagedEnvironmentAuthorizing)? = nil,
|
||||
rpcConnectionWaitTimeout: Duration = .seconds(4)
|
||||
) {
|
||||
self.environmentStore = environmentStore
|
||||
self.credentialStore = credentialStore
|
||||
self.httpTransport = httpTransport
|
||||
self.webSocketConnector = webSocketConnector
|
||||
self.managedAuthorization = managedAuthorization
|
||||
self.rpcConnectionWaitTimeout = rpcConnectionWaitTimeout
|
||||
supportsManagedAuthorization = managedAuthorization != nil
|
||||
}
|
||||
|
||||
@@ -1180,7 +1183,8 @@ public actor EnvironmentRuntime {
|
||||
credentialStore: credentialStore,
|
||||
httpTransport: httpTransport,
|
||||
webSocketConnector: webSocketConnector,
|
||||
managedAuthorization: managedAuthorization
|
||||
managedAuthorization: managedAuthorization,
|
||||
rpcConnectionWaitTimeout: rpcConnectionWaitTimeout
|
||||
)
|
||||
clients[environment.id] = replacement
|
||||
Task { await existing.disconnect() }
|
||||
@@ -1191,7 +1195,8 @@ public actor EnvironmentRuntime {
|
||||
credentialStore: credentialStore,
|
||||
httpTransport: httpTransport,
|
||||
webSocketConnector: webSocketConnector,
|
||||
managedAuthorization: managedAuthorization
|
||||
managedAuthorization: managedAuthorization,
|
||||
rpcConnectionWaitTimeout: rpcConnectionWaitTimeout
|
||||
)
|
||||
clients[environment.id] = client
|
||||
return client
|
||||
@@ -1206,7 +1211,8 @@ public actor EnvironmentRuntime {
|
||||
credentialStore: credentialStore,
|
||||
httpTransport: httpTransport,
|
||||
webSocketConnector: webSocketConnector,
|
||||
managedAuthorization: managedAuthorization
|
||||
managedAuthorization: managedAuthorization,
|
||||
rpcConnectionWaitTimeout: rpcConnectionWaitTimeout
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,5 +54,10 @@ xcodebuild test \
|
||||
-destination "platform=iOS Simulator,id=${SIMULATOR_ID}" \
|
||||
-derivedDataPath "${DERIVED_DATA_PATH}" \
|
||||
-maximum-concurrent-test-simulator-destinations 1 \
|
||||
-parallel-testing-enabled NO \
|
||||
-collect-test-diagnostics never \
|
||||
-test-timeouts-enabled YES \
|
||||
-default-test-execution-time-allowance 30 \
|
||||
-maximum-test-execution-time-allowance 60 \
|
||||
-only-testing:T3CodeTests \
|
||||
CODE_SIGNING_ALLOWED=NO
|
||||
@@ -219,8 +219,7 @@ final class NativeMultiEnvironmentTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testAggregateRefreshRetriesTransientEnvironmentLoadFailures() async throws {
|
||||
let retryObserved = expectation(description: "aggregate refresh retried")
|
||||
let loader = FailOnceAggregateEnvironmentLoader(retryObserved: retryObserved)
|
||||
let loader = FailOnceAggregateEnvironmentLoader()
|
||||
let fixture = try await makeFixture(
|
||||
aggregateRefreshInterval: .milliseconds(5),
|
||||
aggregateEnvironmentLoader: { runtime in
|
||||
@@ -231,19 +230,14 @@ final class NativeMultiEnvironmentTests: XCTestCase {
|
||||
|
||||
_ = try await fixture.client.initialSnapshot()
|
||||
|
||||
await fulfillment(of: [retryObserved], timeout: 1)
|
||||
await loader.waitForCallCount(2)
|
||||
let retryCallCount = await loader.callCount
|
||||
XCTAssertGreaterThanOrEqual(retryCallCount, 2)
|
||||
await fixture.client.disconnect()
|
||||
}
|
||||
|
||||
func testSameClientSnapshotRestartsAggregateRefresh() async throws {
|
||||
let firstLoadStarted = expectation(description: "first aggregate load started")
|
||||
let restartedLoadObserved = expectation(description: "restarted aggregate load observed")
|
||||
let loader = BlockingFirstAggregateEnvironmentLoader(
|
||||
firstLoadStarted: firstLoadStarted,
|
||||
restartedLoadObserved: restartedLoadObserved
|
||||
)
|
||||
let loader = BlockingFirstAggregateEnvironmentLoader()
|
||||
let fixture = try await makeFixture(
|
||||
aggregateRefreshInterval: .milliseconds(5),
|
||||
aggregateEnvironmentLoader: { runtime in
|
||||
@@ -253,11 +247,11 @@ final class NativeMultiEnvironmentTests: XCTestCase {
|
||||
defer { try? FileManager.default.removeItem(at: fixture.directory) }
|
||||
|
||||
_ = try await fixture.client.initialSnapshot()
|
||||
await fulfillment(of: [firstLoadStarted], timeout: 1)
|
||||
await loader.waitForCallCount(1)
|
||||
|
||||
_ = try await fixture.client.initialSnapshot()
|
||||
|
||||
await fulfillment(of: [restartedLoadObserved], timeout: 1)
|
||||
await loader.waitForCallCount(2)
|
||||
let restartedCallCount = await loader.callCount
|
||||
XCTAssertGreaterThanOrEqual(restartedCallCount, 2)
|
||||
await fixture.client.disconnect()
|
||||
@@ -485,7 +479,8 @@ final class NativeMultiEnvironmentTests: XCTestCase {
|
||||
]
|
||||
),
|
||||
httpTransport: transport,
|
||||
webSocketConnector: UnavailableMultiEnvironmentWebSocketConnector()
|
||||
webSocketConnector: UnavailableMultiEnvironmentWebSocketConnector(),
|
||||
rpcConnectionWaitTimeout: .milliseconds(5)
|
||||
)
|
||||
let settings = UserDefaults(
|
||||
suiteName: "t3-native-multi-\(UUID().uuidString)"
|
||||
@@ -506,21 +501,35 @@ final class NativeMultiEnvironmentTests: XCTestCase {
|
||||
}
|
||||
|
||||
private actor FailOnceAggregateEnvironmentLoader {
|
||||
private let retryObserved: XCTestExpectation
|
||||
private(set) var callCount = 0
|
||||
|
||||
init(retryObserved: XCTestExpectation) {
|
||||
self.retryObserved = retryObserved
|
||||
}
|
||||
private var callCountWaiters: [(
|
||||
target: Int,
|
||||
continuation: CheckedContinuation<Void, Never>
|
||||
)] = []
|
||||
|
||||
func load(from runtime: EnvironmentRuntime) async throws -> [Environment] {
|
||||
callCount += 1
|
||||
resumeSatisfiedWaiters()
|
||||
if callCount == 1 {
|
||||
throw URLError(.cannotOpenFile)
|
||||
}
|
||||
retryObserved.fulfill()
|
||||
return try await runtime.environments()
|
||||
}
|
||||
|
||||
func waitForCallCount(_ target: Int) async {
|
||||
guard callCount < target else { return }
|
||||
await withCheckedContinuation { continuation in
|
||||
callCountWaiters.append((target, continuation))
|
||||
}
|
||||
}
|
||||
|
||||
private func resumeSatisfiedWaiters() {
|
||||
let satisfied = callCountWaiters.filter { callCount >= $0.target }
|
||||
callCountWaiters.removeAll { callCount >= $0.target }
|
||||
for waiter in satisfied {
|
||||
waiter.continuation.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private actor CountingAggregateEnvironmentLoader {
|
||||
@@ -532,27 +541,35 @@ private actor CountingAggregateEnvironmentLoader {
|
||||
}
|
||||
|
||||
private actor BlockingFirstAggregateEnvironmentLoader {
|
||||
private let firstLoadStarted: XCTestExpectation
|
||||
private let restartedLoadObserved: XCTestExpectation
|
||||
private(set) var callCount = 0
|
||||
|
||||
init(
|
||||
firstLoadStarted: XCTestExpectation,
|
||||
restartedLoadObserved: XCTestExpectation
|
||||
) {
|
||||
self.firstLoadStarted = firstLoadStarted
|
||||
self.restartedLoadObserved = restartedLoadObserved
|
||||
}
|
||||
private var callCountWaiters: [(
|
||||
target: Int,
|
||||
continuation: CheckedContinuation<Void, Never>
|
||||
)] = []
|
||||
|
||||
func load(from runtime: EnvironmentRuntime) async throws -> [Environment] {
|
||||
callCount += 1
|
||||
resumeSatisfiedWaiters()
|
||||
if callCount == 1 {
|
||||
firstLoadStarted.fulfill()
|
||||
try await Task.sleep(for: .seconds(60))
|
||||
}
|
||||
restartedLoadObserved.fulfill()
|
||||
return try await runtime.environments()
|
||||
}
|
||||
|
||||
func waitForCallCount(_ target: Int) async {
|
||||
guard callCount < target else { return }
|
||||
await withCheckedContinuation { continuation in
|
||||
callCountWaiters.append((target, continuation))
|
||||
}
|
||||
}
|
||||
|
||||
private func resumeSatisfiedWaiters() {
|
||||
let satisfied = callCountWaiters.filter { callCount >= $0.target }
|
||||
callCountWaiters.removeAll { callCount >= $0.target }
|
||||
for waiter in satisfied {
|
||||
waiter.continuation.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private actor RuntimeReplacementConnector: WebSocketConnecting {
|
||||
|
||||
Reference in new issue
Block a user