about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-27 03:30:39 +0000
committerEric Wong <normalperson@yhbt.net>2011-06-27 03:42:43 +0000
commit18318887920773d43b72e9fb6490d3e74674bcf0 (patch)
tree94d0a2d11aad58c9b48e2f726bfe0138d5c1d57f
parentad3bf417b45d50be7b0121b5dacca2bc95b7953b (diff)
downloadraindrops-18318887920773d43b72e9fb6490d3e74674bcf0.tar.gz
Found in the check-warnings target in pkg.mk
-rwxr-xr-xexamples/linux-listener-stats.rb2
-rw-r--r--lib/raindrops/aggregate/last_data_recv.rb3
-rw-r--r--lib/raindrops/aggregate/pmq.rb6
-rw-r--r--lib/raindrops/watcher.rb3
-rw-r--r--test/ipv6_enabled.rb3
-rw-r--r--test/test_aggregate_pmq.rb2
-rw-r--r--test/test_linux.rb44
-rw-r--r--test/test_linux_ipv6.rb20
-rw-r--r--test/test_linux_middleware.rb11
-rw-r--r--test/test_middleware_unicorn.rb2
-rw-r--r--test/test_middleware_unicorn_ipv6.rb2
11 files changed, 56 insertions, 42 deletions
diff --git a/examples/linux-listener-stats.rb b/examples/linux-listener-stats.rb
index 0b0a6dd..1008995 100755
--- a/examples/linux-listener-stats.rb
+++ b/examples/linux-listener-stats.rb
@@ -21,7 +21,7 @@ queued_thresh = -1
 trap(:INT) { exit 130 }
 trap(:PIPE) { exit 0 }
 
-opts = OptionParser.new('', 24, '  ') do |opts|
+OptionParser.new('', 24, '  ') do |opts|
   opts.banner = usage
   opts.on('-d', '--delay=DELAY', Float) { |n| delay = n }
   opts.on('-t', '--queued-threshold=INT', Integer) { |n| queued_thresh = n }
diff --git a/lib/raindrops/aggregate/last_data_recv.rb b/lib/raindrops/aggregate/last_data_recv.rb
index 1e18d76..eca89a2 100644
--- a/lib/raindrops/aggregate/last_data_recv.rb
+++ b/lib/raindrops/aggregate/last_data_recv.rb
@@ -46,7 +46,8 @@ module Raindrops::Aggregate::LastDataRecv
   # for accuracy.
   def self.extended(obj)
     obj.raindrops_aggregate = default_aggregate
-    obj.setsockopt Socket::SOL_TCP, tcp_defer_accept = 9, seconds = 60
+    # obj.setsockopt Socket::SOL_TCP, tcp_defer_accept = 9, seconds = 60
+    obj.setsockopt Socket::SOL_TCP, 9, 60
   end
 
   # :stopdoc:
diff --git a/lib/raindrops/aggregate/pmq.rb b/lib/raindrops/aggregate/pmq.rb
index 6497ce1..a2dd45e 100644
--- a/lib/raindrops/aggregate/pmq.rb
+++ b/lib/raindrops/aggregate/pmq.rb
@@ -229,11 +229,11 @@ class Raindrops::Aggregate::PMQ
   def outliers_high; aggregate.outliers_high; end
 
   # proxy for \Aggregate#to_s
-  def to_s(*args); aggregate.to_s *args; end
+  def to_s(*args); aggregate.to_s(*args); end
 
   # proxy for \Aggregate#each
-  def each; aggregate.each { |*args| yield *args }; end
+  def each; aggregate.each { |*args| yield(*args) }; end
 
   # proxy for \Aggregate#each_nonzero
-  def each_nonzero; aggregate.each_nonzero { |*args| yield *args }; end
+  def each_nonzero; aggregate.each_nonzero { |*args| yield(*args) }; end
 end
diff --git a/lib/raindrops/watcher.rb b/lib/raindrops/watcher.rb
index 6ecd3ed..6d965a5 100644
--- a/lib/raindrops/watcher.rb
+++ b/lib/raindrops/watcher.rb
@@ -228,6 +228,7 @@ class Raindrops::Watcher
   end
 
   def get(env)
+    retried = false
     case env["PATH_INFO"]
     when "/"
       index
@@ -247,7 +248,7 @@ class Raindrops::Watcher
       not_found
     end
     rescue Errno::EDOM
-      raise if defined?(retried)
+      raise if retried
       retried = true
       wait_snapshot
       retry
diff --git a/test/ipv6_enabled.rb b/test/ipv6_enabled.rb
index 319fbef..f02b48f 100644
--- a/test/ipv6_enabled.rb
+++ b/test/ipv6_enabled.rb
@@ -5,6 +5,5 @@ def ipv6_enabled?
   rescue => e
     warn "skipping IPv6 tests, host does not seem to be IPv6 enabled:"
     warn "  #{e.class}: #{e}"
-    return false
-    ipv6_enabled = false
+    false
 end
diff --git a/test/test_aggregate_pmq.rb b/test/test_aggregate_pmq.rb
index caaaf02..9278cba 100644
--- a/test/test_aggregate_pmq.rb
+++ b/test/test_aggregate_pmq.rb
@@ -49,7 +49,7 @@ class TestAggregatePMQ < Test::Unit::TestCase
         pmq.flush
       }
     }
-    workers.each { |pid| assert Process.waitpid2(pid).last.success? }
+    workers.each { |wpid| assert Process.waitpid2(wpid).last.success? }
     pmq.stop_master_loop
     assert Process.waitpid2(pid).last.success?
     assert_equal 400, pmq.count
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/
diff --git a/test/test_linux_ipv6.rb b/test/test_linux_ipv6.rb
index 479b9a2..ec08f28 100644
--- a/test/test_linux_ipv6.rb
+++ b/test/test_linux_ipv6.rb
@@ -22,13 +22,13 @@ class TestLinuxIPv6 < 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
@@ -48,7 +48,7 @@ class TestLinuxIPv6 < 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
@@ -64,7 +64,7 @@ class TestLinuxIPv6 < 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
@@ -72,7 +72,7 @@ class TestLinuxIPv6 < 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
@@ -80,7 +80,7 @@ class TestLinuxIPv6 < 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
@@ -116,7 +116,7 @@ class TestLinuxIPv6 < 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
@@ -127,7 +127,7 @@ class TestLinuxIPv6 < 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
@@ -141,7 +141,7 @@ class TestLinuxIPv6 < 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
@@ -153,6 +153,6 @@ class TestLinuxIPv6 < 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/ && ipv6_enabled?
diff --git a/test/test_linux_middleware.rb b/test/test_linux_middleware.rb
index 670b853..f573225 100644
--- a/test/test_linux_middleware.rb
+++ b/test/test_linux_middleware.rb
@@ -11,12 +11,17 @@ class TestLinuxMiddleware < Test::Unit::TestCase
     @resp_headers = { 'Content-Type' => 'text/plain', 'Content-Length' => '0' }
     @response = [ 200, @resp_headers, [] ]
     @app = lambda { |env| @response }
+    @to_close = []
+  end
+
+  def teardown
+    @to_close.each { |io| io.close unless io.closed? }
   end
 
   def test_unix_listener
     tmp = Tempfile.new("")
     File.unlink(tmp.path)
-    us = UNIXServer.new(tmp.path)
+    @to_close << UNIXServer.new(tmp.path)
     app = Raindrops::Middleware.new(@app, :listeners => [tmp.path])
     linux_extra = "#{tmp.path} active: 0\n#{tmp.path} queued: 0\n"
     response = app.call("PATH_INFO" => "/_raindrops")
@@ -37,8 +42,8 @@ class TestLinuxMiddleware < Test::Unit::TestCase
   def test_unix_listener_queued
     tmp = Tempfile.new("")
     File.unlink(tmp.path)
-    us = UNIXServer.new(tmp.path)
-    uc = UNIXSocket.new(tmp.path)
+    @to_close << UNIXServer.new(tmp.path)
+    @to_close << UNIXSocket.new(tmp.path)
     app = Raindrops::Middleware.new(@app, :listeners => [tmp.path])
     linux_extra = "#{tmp.path} active: 0\n#{tmp.path} queued: 1\n"
     response = app.call("PATH_INFO" => "/_raindrops")
diff --git a/test/test_middleware_unicorn.rb b/test/test_middleware_unicorn.rb
index 0a506e5..805c559 100644
--- a/test/test_middleware_unicorn.rb
+++ b/test/test_middleware_unicorn.rb
@@ -24,7 +24,7 @@ class TestMiddlewareUnicorn < Test::Unit::TestCase
     s = TCPSocket.new @host, @port
     s.write "GET /_raindrops HTTP/1.0\r\n\r\n"
     resp = s.read
-    head, body = resp.split /\r\n\r\n/, 2
+    _, body = resp.split(/\r\n\r\n/, 2)
     assert_match %r{^#@addr_regexp active: 1$}, body
     assert_match %r{^#@addr_regexp queued: 0$}, body
   end
diff --git a/test/test_middleware_unicorn_ipv6.rb b/test/test_middleware_unicorn_ipv6.rb
index edc9d85..146e603 100644
--- a/test/test_middleware_unicorn_ipv6.rb
+++ b/test/test_middleware_unicorn_ipv6.rb
@@ -24,7 +24,7 @@ class TestMiddlewareUnicornIPv6 < Test::Unit::TestCase
     s = TCPSocket.new @host, @port
     s.write "GET /_raindrops HTTP/1.0\r\n\r\n"
     resp = s.read
-    head, body = resp.split /\r\n\r\n/, 2
+    _, body = resp.split(/\r\n\r\n/, 2)
     assert_match %r{^#@addr_regexp active: 1$}, body
     assert_match %r{^#@addr_regexp queued: 0$}, body
   end