Skip to content
Merged
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
20 changes: 19 additions & 1 deletion swift/Tests/AppleTests/AppLifecycleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,27 @@
}

let log = RecordingLogSink()
let stops = Stops()
let stops: Stops
let connectTimeouts = ConnectTimeouts()

/// Each test starts once the process has made its first connect (`firstConnect`), and counts the stops from there.
init() async throws {
try await Self.firstConnect.value
stops = Stops()
}

/// The process's first URLSession connect, made once, before the first test. Before its socket opens, it waits on the system's services (cfprefsd, containermanagerd, runningboardd, configd_sim) for what a process sets up once. In the iOS Simulator on CI, while the simulator's first boot keeps the runner busy, that has taken from about a second to about 30 s, which the tests' waits for a connection (`connectWait`) would count; the process's later connects don't wait for it. URLSession's request timeout (60 s) bounds it, within the first test's time limit; when it fails, every test fails with its error.
static let firstConnect = Task {
let server = try WebSocketServer()
defer { server.stop() }
let port = try await server.start()
let start = ContinuousClock.now
let socket = try await URLSessionTransport().connect(
url: "ws://127.0.0.1:\(port)/", secProtocol: nil)
print("[lifecycle] the process's first connect took \(ContinuousClock.now - start)")
await socket.close(code: 1000, reason: "")
}

/// Whether the process was stopped during the test: a timer on a queue of its own came back more than a second late, as `within`'s polls do.
final class Stops: @unchecked Sendable {
private let queue = DispatchQueue(label: "AppLifecycleTests.Stops")
Expand Down
Loading