about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-03-13 20:48:26 +0000
committerEric Wong <e@80x24.org>2014-03-13 20:48:26 +0000
commitc28223d381a6714cf005843e029c6ef211980c72 (patch)
tree7ec524339a79966417ec80e8147e7470cbab2de8 /test
parente59f1c0c1018b4e252585bcd4ca0f688689ae8a5 (diff)
parentf46aea4aa26d3c3c5613d6800b2832cddb14b754 (diff)
downloadyahns-c28223d381a6714cf005843e029c6ef211980c72.tar.gz
* origin/freebsd:
  implement kqueue and sendfile compatibility support
  test: log skipped tests on non-Linux systems
  test_server: check_client_connection uses Unix sockets
  test_client_expire: add delays for non-Linux OSes
  wbuf_common: avoid trysendfile on empty sf_count
  sigevent_pipe: kgio_wait_writable takes variadic args
  queue_quitter_pipe: do not prematurely close reader
Diffstat (limited to 'test')
-rw-r--r--test/test_buffer_tmpdir.rb10
-rw-r--r--test/test_client_expire.rb10
-rw-r--r--test/test_mt_accept.rb4
-rw-r--r--test/test_server.rb25
-rw-r--r--test/test_wbuf.rb4
5 files changed, 41 insertions, 12 deletions
diff --git a/test/test_buffer_tmpdir.rb b/test/test_buffer_tmpdir.rb
index c7665f6..8461346 100644
--- a/test/test_buffer_tmpdir.rb
+++ b/test/test_buffer_tmpdir.rb
@@ -9,12 +9,18 @@ class TestBufferTmpdir < Testcase
   attr_reader :ino, :tmpdir
 
   def setup
-    @ino = SleepyPenguin::Inotify.new(:CLOEXEC)
+    @ino = nil
+    begin
+      @ino = SleepyPenguin::Inotify.new(:CLOEXEC)
+    rescue
+      skip "test needs inotify"
+    end
     @tmpdir = Dir.mktmpdir
     server_helper_setup
   end
 
   def teardown
+    return unless @ino
     server_helper_teardown
     @ino.close
     FileUtils.rm_rf @tmpdir
@@ -100,4 +106,4 @@ class TestBufferTmpdir < Testcase
     c.close if c
     quit_wait(pid)
   end
-end if SleepyPenguin.const_defined?(:Inotify)
+end
diff --git a/test/test_client_expire.rb b/test/test_client_expire.rb
index bdf0cb4..4f20803 100644
--- a/test/test_client_expire.rb
+++ b/test/test_client_expire.rb
@@ -149,9 +149,17 @@ class TestClientExpire < Testcase
         Process.waitpid2(_pid)
       end
     end
+
+    # this seems to be needed in Debian GNU/kFreeBSD
+    linux = !!(RUBY_PLATFORM =~ /linux/)
+    sleep(1) unless linux
+
     [ f, s ].each do |io|
       assert_raises(Errno::EPIPE,Errno::ECONNRESET) do
-        req.each_byte { |b| io.write(b.chr) }
+        req.each_byte do |b|
+          io.write(b.chr)
+          sleep(0.01) unless linux
+        end
       end
       io.close
     end
diff --git a/test/test_mt_accept.rb b/test/test_mt_accept.rb
index e006af8..37813d4 100644
--- a/test/test_mt_accept.rb
+++ b/test/test_mt_accept.rb
@@ -10,6 +10,8 @@ class TestMtAccept < Testcase
   alias teardown server_helper_teardown
 
   def test_mt_accept
+    skip "Linux kernel required" unless RUBY_PLATFORM =~ /linux/
+    skip "/proc not mounted" unless File.directory?("/proc")
     err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
     opts = { threads: 1 }
     cfg.instance_eval do
@@ -45,4 +47,4 @@ class TestMtAccept < Testcase
   ensure
     quit_wait(pid)
   end
-end if RUBY_PLATFORM =~ /linux/ && File.directory?("/proc")
+end
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
diff --git a/test/test_wbuf.rb b/test/test_wbuf.rb
index 25cdeba..644c76b 100644
--- a/test/test_wbuf.rb
+++ b/test/test_wbuf.rb
@@ -81,8 +81,8 @@ class TestWbuf < Testcase
     assert_equal b, IO.select([b], nil, nil, 5)[0][0]
     b.read(nr - 2) if nr > 2
     assert_equal b, IO.select([b], nil, nil, 5)[0][0]
-    assert_equal "HI", b.read(2)
-    assert_equal false, wbuf.wbuf_flush(a)
+    assert_equal "HI", b.read(2), "read the end of the response"
+    assert_equal true, wbuf.wbuf_flush(a)
   ensure
     a.close
     b.close