about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-31 23:54:20 +0000
committerEric Wong <normalperson@yhbt.net>2009-10-31 16:55:53 -0700
commit2d54043a213671866fb827d937d7814c9171f5e4 (patch)
treef1d0b667da665018b90ec36652f3ccfe8c1eed0c
parent9f707bc02ffba4e3b792aa7da325f9e550ea27c2 (diff)
downloadunicorn-2d54043a213671866fb827d937d7814c9171f5e4.tar.gz
Just write bytes to the file instead and track its
size increase instead of its mode.  As of now all
the unit tests pass under FreeBSD 7.2.
-rw-r--r--test/unit/test_signals.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/test/unit/test_signals.rb b/test/unit/test_signals.rb
index d409da3..eb2af0b 100644
--- a/test/unit/test_signals.rb
+++ b/test/unit/test_signals.rb
@@ -26,14 +26,15 @@ class SignalsTest < Test::Unit::TestCase
     @bs = 1 * 1024 * 1024
     @count = 100
     @port = unused_port
-    tmp = @tmp = Tempfile.new('unicorn.sock')
+    @sock = Tempfile.new('unicorn.sock')
+    @tmp = Tempfile.new('unicorn.write')
+    @tmp.sync = true
+    File.unlink(@sock.path)
     File.unlink(@tmp.path)
-    n = 0
-    tmp.chmod(0)
     @server_opts = {
-      :listeners => [ "127.0.0.1:#@port", @tmp.path ],
+      :listeners => [ "127.0.0.1:#@port", @sock.path ],
       :after_fork => lambda { |server,worker|
-        trap(:HUP) { tmp.chmod(n += 1) }
+        trap(:HUP) { @tmp.syswrite('.') }
       },
     }
     @server = nil
@@ -143,7 +144,7 @@ class SignalsTest < Test::Unit::TestCase
     end
     assert pid > 0, "pid not positive: #{pid.inspect}"
     read = buf.size
-    mode_before = @tmp.stat.mode
+    size_before = @tmp.stat.size
     assert_raises(EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,
                   Errno::EBADF) do
       loop do
@@ -156,8 +157,10 @@ class SignalsTest < Test::Unit::TestCase
 
     redirect_test_io { @server.stop(true) }
     # can't check for == since pending signals get merged
-    assert mode_before < @tmp.stat.mode
-    assert_equal(read - header_len, @bs * @count)
+    assert size_before < @tmp.stat.size
+    got = read - header_len
+    expect = @bs * @count
+    assert_equal(expect, got, "expect=#{expect} got=#{got}")
     assert_nothing_raised { sock.close }
   end
 
@@ -183,7 +186,7 @@ class SignalsTest < Test::Unit::TestCase
     sock.syswrite("PUT / HTTP/1.0\r\n")
     sock.syswrite("Content-Length: #{@bs * @count}\r\n\r\n")
     1000.times { Process.kill(:HUP, pid) }
-    mode_before = @tmp.stat.mode
+    size_before = @tmp.stat.size
     killer = fork { loop { Process.kill(:HUP, pid); sleep(0.0001) } }
     buf = ' ' * @bs
     @count.times { sock.syswrite(buf) }
@@ -191,7 +194,7 @@ class SignalsTest < Test::Unit::TestCase
     Process.waitpid2(killer)
     redirect_test_io { @server.stop(true) }
     # can't check for == since pending signals get merged
-    assert mode_before < @tmp.stat.mode
+    assert size_before < @tmp.stat.size
     assert_equal pid, sock.sysread(4096)[/\r\nX-Pid: (\d+)\r\n/, 1].to_i
     sock.close
   end