From 806728f89edc6841dcf9296e3d34f1df8b095503 Mon Sep 17 00:00:00 2001 From: Simon Whitty Date: Tue, 24 Oct 2023 20:51:50 +1100 Subject: [PATCH] Updating tests --- FlyingFox/Tests/HTTPServerTests.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/FlyingFox/Tests/HTTPServerTests.swift b/FlyingFox/Tests/HTTPServerTests.swift index d14b6aa8..0b502ae0 100644 --- a/FlyingFox/Tests/HTTPServerTests.swift +++ b/FlyingFox/Tests/HTTPServerTests.swift @@ -68,6 +68,18 @@ final class HTTPServerTests: XCTestCase { } } + func testThrowsError_WhenSocketAlreadyListening() async throws { + let server = HTTPServer.make(port: 42185) + let socket = try await server.makeSocketAndListen() + defer { try! socket.close() } + + await AsyncAssertThrowsError(try await server.start(), of: SocketError.self) { + XCTAssertTrue( + $0.errorDescription?.contains("Address already in use") == true + ) + } + } + func testRestarts_AfterStopped() async throws { let server = HTTPServer.make() try await startServer(server) @@ -397,7 +409,7 @@ extension HTTPServer { timeout: TimeInterval = 15, logger: Logging? = nil, handler: HTTPHandler? = nil) -> HTTPServer { - HTTPServer(port: port, + HTTPServer(address: .loopback(port: port), timeout: timeout, logger: logger, handler: handler)