From aaa16ebf9f823b6b48c24bd5ec1785e3bdd15b76 Mon Sep 17 00:00:00 2001 From: Qiu Yuzhou Date: Sat, 24 Oct 2026 03:35:29 +0800 Subject: [PATCH] test(http): shorten first-byte timeout check --- .../Connectivity/ConnectivityHTTPTests.swift | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/ShadowsocksX-NG2/Tests/Connectivity/ConnectivityHTTPTests.swift b/ShadowsocksX-NG2/Tests/Connectivity/ConnectivityHTTPTests.swift index 0b850e79..fb09c4c1 100644 --- a/ShadowsocksX-NG2/Tests/Connectivity/ConnectivityHTTPTests.swift +++ b/ShadowsocksX-NG2/Tests/Connectivity/ConnectivityHTTPTests.swift @@ -119,22 +119,17 @@ struct ConnectivityHTTPTests { #expect(proxy.requests.isEmpty) } - @Test func requestHasOneFiveSecondDeadline() async throws { + @Test(.timeLimit(.minutes(1))) + func timesOutWhileWaitingForFirstByte() async throws { let proxy = try HeaderProxy(status: nil) defer { proxy.stop() } let port = try await proxy.start() - let id = NodeID.fresh() - let module = ServerConnectivity( - configuration: { _ in Self.server }, - measure: { _, url, _ in - await ConnectivityHTTPRequest().perform(url: url, proxyPort: port) - }) - module.setURL(URL(string: "http://target.invalid/slow")!) - let started = ContinuousClock.now - await module.wait(for: module.test([id])) - #expect(module.history(for: id).first?.outcome == .requestTimeout) - #expect(ContinuousClock.now - started >= .seconds(5)) - #expect(ContinuousClock.now - started < .seconds(6)) + let result = await ConnectivityHTTPRequest().observe( + url: URL(string: "http://target.invalid/slow")!, targetIP: nil, proxyPort: port, + timeout: 0.5) + #expect(result.outcome == .requestTimeout) + #expect(result.failureStage == "first_byte") + #expect(result.totalMilliseconds >= 500) #expect(proxy.requests.count == 1) }