diff options
author | Eric Wong <e@80x24.org> | 2014-02-08 03:20:56 -0500 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2014-02-08 08:35:41 +0000 |
commit | 2f7660ed8124bef150c48ce14f9df759e467e44c (patch) | |
tree | b14f0b74d02221db7c5c973b11add942d50388e7 /test | |
parent | e86802a1f3f7ac34d32483f9d5de7e627e984db7 (diff) | |
download | yahns-2f7660ed8124bef150c48ce14f9df759e467e44c.tar.gz |
TCP socket timing is too varied over different OSes, Unix sockets seem to test more reliably than TCP ones on my Debian GNU/kFreeBSD system.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_server.rb | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/test/test_server.rb b/test/test_server.rb index f4c66ae..96fc704 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -178,11 +178,14 @@ class TestServer < Testcase end def test_check_client_connection + tmpdir = Dir.mktmpdir + sock = "#{tmpdir}/sock" + unix_srv = UNIXServer.new(sock) + unix_srv.close_on_exec = true msgs = %w(ZZ zz) err = @err cfg = Yahns::Config.new bpipe = cloexec_pipe - host, port = @srv.addr[3], @srv.addr[1] cfg.instance_eval do ru = lambda { |e| case e['PATH_INFO'] @@ -205,7 +208,7 @@ class TestServer < Testcase } GTL.synchronize { app(:rack, ru) { - listen "#{host}:#{port}" + listen sock check_client_connection true # needed to avoid concurrency with check_client_connection queue { worker_threads 1 } @@ -223,12 +226,13 @@ class TestServer < Testcase pid = fork do bpipe[1].close - ENV["YAHNS_FD"] = @srv.fileno.to_s + ENV["YAHNS_FD"] = unix_srv.fileno.to_s srv.start.join end bpipe[0].close - a = get_tcp_client(host, port) - b = get_tcp_client(host, port) + a = UNIXSocket.new(sock) + b = UNIXSocket.new(sock) + b.close_on_exec = a.close_on_exec = true a.write("GET /sleep HTTP/1.0\r\n\r\n") r = IO.select([a], nil, nil, 4) assert r, "nothing ready" @@ -250,10 +254,19 @@ class TestServer < Testcase assert_equal msgs.join, buf.split(/\r\n\r\n/)[1] # do things still work? - run_client(host, port) { |res| assert_equal "HI", res.body } + c = UNIXSocket.new(sock) + c.write "GET /\r\n\r\n" + assert_equal "HI", c.read + c.close a.close + rescue => e + warn e.class + warn e.message + warn e.backtrace.join("\n") ensure + unix_srv.close quit_wait(pid) + FileUtils.rm_rf(tmpdir) end def test_mp |