Skip to content

Commit 958734a

Browse files
tmmampagent
andauthored
test(zero-swift): report what the server saw when a mid-frame reconnect never opens (#109)
On the iOS Simulator the client's reconnect after a cut-off frame stopped at "Connecting to …" for 10 s. The failure now lists when the server got each upgrade request and answered it, so it shows whether the request never came or the client never took the answer. Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: Amp <amp@ampcode.com>
1 parent 1d8e444 commit 958734a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎swift/Tests/E2ETests/TransportProbeTests.swift‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,22 @@ struct TransportProbeTests {
227227
func clientReconnectsAfterTheServerGoesAwayMidFrame(_ kind: TransportKind) async throws {
228228
for binary in [false, true] {
229229
let connections = Box(0)
230+
// What the server saw, in ms from the start, so that a reconnect that never opens shows whether the server answered its handshake.
231+
let start = ContinuousClock.now
232+
let seen = Box<[String]>([])
233+
let saw: @Sendable (String) -> Void = { event in
234+
let ms = (ContinuousClock.now - start) / .milliseconds(1)
235+
seen.withLock { $0.append("\(event) at \(Int(ms)) ms") }
236+
}
230237
let server = try await ScriptedServer { c in
231238
let n = connections.withLock {
232239
$0 += 1
233240
return $0
234241
}
235-
await c.write(c.accept() + ScriptedServer.text(#"["connected",{"wsid":"w\#(n)"}]"#))
242+
saw("connection \(n) upgrade request")
243+
let upgrade = c.accept()
244+
await c.write(upgrade + ScriptedServer.text(#"["connected",{"wsid":"w\#(n)"}]"#))
245+
saw("connection \(n) answered")
236246
if n == 1 {
237247
try? await Task.sleep(for: .milliseconds(300))
238248
let row =
@@ -265,6 +275,7 @@ struct TransportProbeTests {
265275
"[probe] \(kind) client, server gone mid-\(binary ? "binary" : "text") frame: reconnected \(reconnected), states \(states), \(zero.connection.state)"
266276
)
267277
if !reconnected {
278+
print("[probe] server: \(seen.withLock { $0 })")
268279
for line in logs.all.suffix(8) { print("[probe] \(line.prefix(300))") }
269280
}
270281
#expect(reconnected, "binary \(binary): \(zero.connection.state)")

0 commit comments

Comments
 (0)