diff --git a/FlyingSocks/Tests/AsyncSocketTests.swift b/FlyingSocks/Tests/AsyncSocketTests.swift index 46b7f949..97d193b8 100644 --- a/FlyingSocks/Tests/AsyncSocketTests.swift +++ b/FlyingSocks/Tests/AsyncSocketTests.swift @@ -148,6 +148,14 @@ final class AsyncSocketTests: XCTestCase { try s1.close() await AsyncAssertThrowsError(try s1.close(), of: SocketError.self) } + + func testSocketSequence_Ends_WhenDisconnected() async throws { + let s1 = try AsyncSocket.makeListening(pool: DisconnectedPool()) + var sockets = s1.sockets + await AsyncAssertNil( + try await sockets.next() + ) + } } extension AsyncSocket { @@ -156,6 +164,16 @@ extension AsyncSocket { try await make(pool: .client) } + static func makeListening(pool: AsyncSocketPool) throws -> AsyncSocket { + let address = sockaddr_un.unix(path: "foxsocks") + try? Socket.unlink(address) + let socket = try Socket(domain: AF_UNIX, type: Socket.stream) + try socket.setValue(true, for: .localAddressReuse) + try socket.bind(to: address) + try socket.listen() + return try AsyncSocket(socket: socket, pool: pool) + } + static func make(pool: AsyncSocketPool) throws -> AsyncSocket { let socket = try Socket(domain: AF_UNIX, type: Socket.stream) return try AsyncSocket(socket: socket, pool: pool) @@ -188,3 +206,14 @@ extension AsyncSocket { return string } } + +struct DisconnectedPool: AsyncSocketPool { + + func prepare() async throws { } + + func run() async throws { } + + func suspendSocket(_ socket: FlyingSocks.Socket, untilReadyFor events: FlyingSocks.Socket.Events) async throws { + throw SocketError.disconnected + } +}