From 2a0f7a7e74344cc67655b52c6a1a12e5236d1491 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 19 Aug 2026 14:57:03 +1200 Subject: [PATCH] Make UNIX endpoint connection test deterministic Assisted-By: devx/3ed43c18-3c9a-4ad9-a6f5-6668caa29658 --- test/io/endpoint/unix_endpoint.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/test/io/endpoint/unix_endpoint.rb b/test/io/endpoint/unix_endpoint.rb index c9895e8..053a1b7 100644 --- a/test/io/endpoint/unix_endpoint.rb +++ b/test/io/endpoint/unix_endpoint.rb @@ -29,33 +29,30 @@ expect(server).to be_a(Socket) - server.listen(1) - thread = Thread.new do - while true - peer, address = server.accept - peer.close - end - ensure - server&.close + accepted_socket, _address = server.accept + accepted_socket.close end - expect(endpoint).to be(:bound?) - - # Wait for the server to start accepting connections: - # I noticed on slow CI, that the connect would fail because the server has not called `#accept` yet, even if it's bound and listening! - Thread.pass until thread.status == "sleep" - endpoint.connect do |socket| expect(socket).to be_a(Socket) # Wait for the connection to be closed. socket.wait_readable - - socket.close end + + thread.value ensure + sockets&.each(&:close) thread&.kill + thread&.join + end + + it "can determine whether it is bound" do + sockets = endpoint.bind + + expect(endpoint).to be(:bound?) + ensure sockets&.each(&:close) end