diff options
author | Eric Wong <e@80x24.org> | 2013-10-21 20:39:23 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2013-10-21 20:39:23 +0000 |
commit | bba715c124c39cc48f25bf998cd55e709674c15f (patch) | |
tree | 298793ad51285df811fc033469a34256f8ec2f23 /test/test_bin.rb | |
parent | fbed65999dc8e1dd4b21a2b54a3ad3afcc5b0849 (diff) | |
download | yahns-bba715c124c39cc48f25bf998cd55e709674c15f.tar.gz |
close/FD_CLOEXEC may be insufficient since the socket could be released asynchronously, leading to occasional test failures. Even with a synchronous close/FD_CLOEXEC, there's a chance of a race because the server does not bind the socket right away.
Diffstat (limited to 'test/test_bin.rb')
-rw-r--r-- | test/test_bin.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/test/test_bin.rb b/test/test_bin.rb index 610c99d..074127c 100644 --- a/test/test_bin.rb +++ b/test/test_bin.rb @@ -42,20 +42,30 @@ class TestBin < Testcase @cmd.concat(%W(-D -c #{cfg.path})) addr = IO.pipe pid = fork do + opts = { close_others: true } addr[0].close if inherit - @cmd << { @srv.fileno => @srv } + opts[@srv.fileno] = @srv ENV["YAHNS_FD"] = @srv.fileno.to_s else # we must create the socket inside the child and tell the parent # about it to avoid sharing @srv = TCPServer.new(ENV["TEST_HOST"] || "127.0.0.1", 0) - @srv.close_on_exec = true # needed for 1.9.3 end + @cmd << opts host, port = @srv.addr[3], @srv.addr[1] listen = ENV["YAHNS_TEST_LISTEN"] = "#{host}:#{port}" addr[1].write(listen) addr[1].close + + # close/FD_CLOEXEC may be insufficient since the socket could be + # released asynchronously, leading to occasional test failures. + # Even with a synchronous FD_CLOEXEC, there's a chance of a race + # because the server does not bind right away. + unless inherit + @srv.shutdown + @srv.close + end exec(*@cmd) end addr[1].close |