about summary refs log tree commit homepage
path: root/test/test_linux.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_linux.rb')
-rw-r--r--test/test_linux.rb44
1 files changed, 26 insertions, 18 deletions
diff --git a/test/test_linux.rb b/test/test_linux.rb
index 45dc2e0..65f25e0 100644
--- a/test/test_linux.rb
+++ b/test/test_linux.rb
@@ -11,6 +11,14 @@ class TestLinux < Test::Unit::TestCase
 
   TEST_ADDR = ENV['UNICORN_TEST_ADDR'] || '127.0.0.1'
 
+  def setup
+    @to_close = []
+  end
+
+  def teardown
+    @to_close.each { |io| io.close unless io.closed? }
+  end
+
   def test_unix
     tmp = Tempfile.new("\xde\xad\xbe\xef") # valid path, really :)
     File.unlink(tmp.path)
@@ -20,19 +28,19 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 0, stats[tmp.path].active
     assert_equal 0, stats[tmp.path].queued
 
-    uc0 = UNIXSocket.new(tmp.path)
+    @to_close << UNIXSocket.new(tmp.path)
     stats = unix_listener_stats([tmp.path])
     assert_equal 1, stats.size
     assert_equal 0, stats[tmp.path].active
     assert_equal 1, stats[tmp.path].queued
 
-    uc1 = UNIXSocket.new(tmp.path)
+    @to_close << UNIXSocket.new(tmp.path)
     stats = unix_listener_stats([tmp.path])
     assert_equal 1, stats.size
     assert_equal 0, stats[tmp.path].active
     assert_equal 2, stats[tmp.path].queued
 
-    ua0 = us.accept
+    @to_close << us.accept
     stats = unix_listener_stats([tmp.path])
     assert_equal 1, stats.size
     assert_equal 1, stats[tmp.path].active
@@ -43,17 +51,17 @@ class TestLinux < Test::Unit::TestCase
     tmp = Tempfile.new("\xde\xad\xbe\xef") # valid path, really :)
     File.unlink(tmp.path)
     us = UNIXServer.new(tmp.path)
-    uc0 = UNIXSocket.new(tmp.path)
+    @to_close << UNIXSocket.new(tmp.path)
     stats = unix_listener_stats
     assert_equal 0, stats[tmp.path].active
     assert_equal 1, stats[tmp.path].queued
 
-    uc1 = UNIXSocket.new(tmp.path)
+    @to_close << UNIXSocket.new(tmp.path)
     stats = unix_listener_stats
     assert_equal 0, stats[tmp.path].active
     assert_equal 2, stats[tmp.path].queued
 
-    ua0 = us.accept
+    @to_close << us.accept
     stats = unix_listener_stats
     assert_equal 1, stats[tmp.path].active
     assert_equal 1, stats[tmp.path].queued
@@ -69,13 +77,13 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 0, stats[addr].queued
     assert_equal 0, stats[addr].active
 
-    c = TCPSocket.new(TEST_ADDR, port)
+    @to_close << TCPSocket.new(TEST_ADDR, port)
     stats = tcp_listener_stats(addrs)
     assert_equal 1, stats.size
     assert_equal 1, stats[addr].queued
     assert_equal 0, stats[addr].active
 
-    sc = s.accept
+    @to_close << s.accept
     stats = tcp_listener_stats(addrs)
     assert_equal 1, stats.size
     assert_equal 0, stats[addr].queued
@@ -93,13 +101,13 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 0, stats[addr].queued
     assert_equal 0, stats[addr].active
 
-    c = TCPSocket.new(TEST_ADDR, port)
+    @to_close << TCPSocket.new(TEST_ADDR, port)
     stats = tcp_listener_stats(addrs, nlsock)
     assert_equal 1, stats.size
     assert_equal 1, stats[addr].queued
     assert_equal 0, stats[addr].active
 
-    sc = s.accept
+    @to_close << s.accept
     stats = tcp_listener_stats(addrs, nlsock)
     assert_equal 1, stats.size
     assert_equal 0, stats[addr].queued
@@ -121,7 +129,7 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 0, stats[addr2].queued
     assert_equal 0, stats[addr2].active
 
-    c1 = TCPSocket.new(TEST_ADDR, port1)
+    @to_close << TCPSocket.new(TEST_ADDR, port1)
     stats = tcp_listener_stats(addrs)
     assert_equal 2, stats.size
     assert_equal 1, stats[addr1].queued
@@ -137,7 +145,7 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 0, stats[addr2].queued
     assert_equal 0, stats[addr2].active
 
-    c2 = TCPSocket.new(TEST_ADDR, port2)
+    @to_close << TCPSocket.new(TEST_ADDR, port2)
     stats = tcp_listener_stats(addrs)
     assert_equal 2, stats.size
     assert_equal 0, stats[addr1].queued
@@ -145,7 +153,7 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 1, stats[addr2].queued
     assert_equal 0, stats[addr2].active
 
-    c3 = TCPSocket.new(TEST_ADDR, port2)
+    @to_close << TCPSocket.new(TEST_ADDR, port2)
     stats = tcp_listener_stats(addrs)
     assert_equal 2, stats.size
     assert_equal 0, stats[addr1].queued
@@ -153,7 +161,7 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 2, stats[addr2].queued
     assert_equal 0, stats[addr2].active
 
-    sc2 = s2.accept
+    @to_close << s2.accept
     stats = tcp_listener_stats(addrs)
     assert_equal 2, stats.size
     assert_equal 0, stats[addr1].queued
@@ -184,7 +192,7 @@ class TestLinux < Test::Unit::TestCase
       fork do
         rda.close
         wrb.close
-        socks = (1..nr_sock).map { s.accept }
+        @to_close.concat((1..nr_sock).map { s.accept })
         wra.syswrite('.')
         wra.close
         rdb.sysread(1) # wait for parent to nuke us
@@ -195,7 +203,7 @@ class TestLinux < Test::Unit::TestCase
       fork do
         rda.close
         wrb.close
-        socks = (1..nr_sock).map { TCPSocket.new(TEST_ADDR, port) }
+        @to_close.concat((1..nr_sock).map { TCPSocket.new(TEST_ADDR, port) })
         wra.syswrite('.')
         wra.close
         rdb.sysread(1) # wait for parent to nuke us
@@ -209,7 +217,7 @@ class TestLinux < Test::Unit::TestCase
     expect = { addr => Raindrops::ListenStats[nr_sock * nr_proc, 0] }
     assert_equal expect, stats
 
-    uno_mas = TCPSocket.new(TEST_ADDR, port)
+    @to_close << TCPSocket.new(TEST_ADDR, port)
     stats = tcp_listener_stats(addrs)
     expect = { addr => Raindrops::ListenStats[nr_sock * nr_proc, 1] }
     assert_equal expect, stats
@@ -221,6 +229,6 @@ class TestLinux < Test::Unit::TestCase
 
     wrb.syswrite('.' * (nr_proc * 2)) # broadcast a wakeup
     statuses = Process.waitall
-    statuses.each { |(pid,status)| assert status.success?, status.inspect }
+    statuses.each { |(_,status)| assert status.success?, status.inspect }
   end if ENV["STRESS"].to_i != 0
 end if RUBY_PLATFORM =~ /linux/