about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <bofh@yhbt.net>2020-01-06 09:54:50 +0000
committerEric Wong <e@80x24.org>2020-01-06 09:56:28 +0000
commit85486f9af18e4f249f23253e3b251e685b323912 (patch)
treebb98971324a6416d782ec3deab39e4b404cda6c3
parent6ec35b0be879970931a67f5aa84b0e12099b12fd (diff)
downloadraindrops-85486f9af18e4f249f23253e3b251e685b323912.tar.gz
Newer rubies have more warnings
-rwxr-xr-xexamples/linux-listener-stats.rb3
-rw-r--r--lib/raindrops/aggregate/pmq.rb12
-rw-r--r--lib/raindrops/linux.rb9
-rw-r--r--test/ipv6_enabled.rb8
-rw-r--r--test/test_linux.rb5
-rw-r--r--test/test_linux_all_tcp_listen_stats_leak.rb4
-rw-r--r--test/test_raindrops.rb2
-rw-r--r--test/test_tcp_info.rb8
-rw-r--r--test/test_watcher.rb18
9 files changed, 34 insertions, 35 deletions
diff --git a/examples/linux-listener-stats.rb b/examples/linux-listener-stats.rb
index 1008995..7e767da 100755
--- a/examples/linux-listener-stats.rb
+++ b/examples/linux-listener-stats.rb
@@ -15,7 +15,6 @@ end
 usage = "Usage: #$0 [-d DELAY] [-t QUEUED_THRESHOLD] ADDR..."
 ARGV.size > 0 or abort usage
 delay = false
-all = false
 queued_thresh = -1
 # "normal" exits when driven on the command-line
 trap(:INT) { exit 130 }
@@ -25,7 +24,7 @@ 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 }
-  opts.on('-a', '--all') { all = true }
+  opts.on('-a', '--all') { } # noop
   opts.parse! ARGV
 end
 
diff --git a/lib/raindrops/aggregate/pmq.rb b/lib/raindrops/aggregate/pmq.rb
index 8623cb1..64d0a4f 100644
--- a/lib/raindrops/aggregate/pmq.rb
+++ b/lib/raindrops/aggregate/pmq.rb
@@ -142,8 +142,8 @@ class Raindrops::Aggregate::PMQ
       warn "Unhandled exception in #{__FILE__}:#{__LINE__}: #{e}"
       break
     end while true
-    ensure
-      flush_master
+  ensure
+    flush_master
   end
 
   # Loads the last shared \Aggregate from the master thread/process
@@ -175,14 +175,14 @@ class Raindrops::Aggregate::PMQ
   # worker thread or process
   def stop_master_loop
     sleep 0.1 until mq_send(false)
-    rescue Errno::EINTR
-      retry
+  rescue Errno::EINTR
+    retry
   end
 
   def lock! io, type # :nodoc:
     io.fcntl Fcntl::F_SETLKW, type
-    rescue Errno::EINTR
-      retry
+  rescue Errno::EINTR
+    retry
   end
 
   # we use both a mutex for thread-safety and fcntl lock for process-safety
diff --git a/lib/raindrops/linux.rb b/lib/raindrops/linux.rb
index 4166ec7..9842ae1 100644
--- a/lib/raindrops/linux.rb
+++ b/lib/raindrops/linux.rb
@@ -14,8 +14,7 @@ module Raindrops::Linux
   # The standard proc path for active UNIX domain sockets, feel free to call
   # String#replace on this if your /proc is mounted in a non-standard location
   # for whatever reason
-  PROC_NET_UNIX_ARGS = %w(/proc/net/unix)
-  defined?(::Encoding) and PROC_NET_UNIX_ARGS.push({ :encoding => "binary" })
+  PROC_NET_UNIX_ARGS = [ '/proc/net/unix', { encoding: "binary" }]
 
   # Get ListenStats from an array of +paths+
   #
@@ -42,11 +41,11 @@ module Raindrops::Linux
     else
       paths = paths.map do |path|
         path = path.dup
-        path.force_encoding(Encoding::BINARY) if defined?(Encoding)
+        path.force_encoding(Encoding::BINARY)
         if File.symlink?(path)
           link = path
           path = File.readlink(link)
-          path.force_encoding(Encoding::BINARY) if defined?(Encoding)
+          path.force_encoding(Encoding::BINARY)
           rv[link] = rv[path] # vivify ListenerStats
         else
           rv[path] # vivify ListenerStats
@@ -57,7 +56,7 @@ module Raindrops::Linux
     paths = /^\w+: \d+ \d+ (\d+) \d+ (\d+)\s+\d+ (#{paths.join('|')})$/n
 
     # no point in pread since we can't stat for size on this file
-    File.read(*PROC_NET_UNIX_ARGS).scan(paths) do |s|
+    File.read(PROC_NET_UNIX_ARGS[0], encoding: 'binary').scan(paths) do |s|
       path = s[-1]
       case s[0]
       when "00000000" # client sockets
diff --git a/test/ipv6_enabled.rb b/test/ipv6_enabled.rb
index f02b48f..c4c9709 100644
--- a/test/ipv6_enabled.rb
+++ b/test/ipv6_enabled.rb
@@ -2,8 +2,8 @@ def ipv6_enabled?
   tmp = TCPServer.new(ENV["TEST_HOST6"] || '::1', 0)
   tmp.close
   true
-  rescue => e
-    warn "skipping IPv6 tests, host does not seem to be IPv6 enabled:"
-    warn "  #{e.class}: #{e}"
-    false
+rescue => e
+  warn "skipping IPv6 tests, host does not seem to be IPv6 enabled:"
+  warn "  #{e.class}: #{e}"
+  false
 end
diff --git a/test/test_linux.rb b/test/test_linux.rb
index bfefcc4..7808469 100644
--- a/test/test_linux.rb
+++ b/test/test_linux.rb
@@ -76,6 +76,7 @@ class TestLinux < Test::Unit::TestCase
 
     assert_equal 0, stats[tmp.path].active
     assert_equal 0, stats[tmp.path].queued
+    us.close
   end
 
   def test_unix_resolves_symlinks
@@ -151,8 +152,8 @@ class TestLinux < Test::Unit::TestCase
     assert_equal 1, stats.size
     assert_equal 0, stats[addr].queued
     assert_equal 1, stats[addr].active
-    ensure
-      nlsock.close
+  ensure
+    nlsock.close
   end
 
   def test_tcp_multi
diff --git a/test/test_linux_all_tcp_listen_stats_leak.rb b/test/test_linux_all_tcp_listen_stats_leak.rb
index 7368220..7be46d4 100644
--- a/test/test_linux_all_tcp_listen_stats_leak.rb
+++ b/test/test_linux_all_tcp_listen_stats_leak.rb
@@ -37,7 +37,7 @@ class TestLinuxAllTcpListenStatsLeak < Test::Unit::TestCase
     end
     cur_kb = rss_kb
     p [ :cur_kb, cur_kb ]
-    ensure
-      s.close
+  ensure
+    s.close
   end
 end if ENV["STRESS"].to_i != 0
diff --git a/test/test_raindrops.rb b/test/test_raindrops.rb
index 67089b7..0749694 100644
--- a/test/test_raindrops.rb
+++ b/test/test_raindrops.rb
@@ -134,7 +134,7 @@ class TestRaindrops < Test::Unit::TestCase
     assert_equal 0, rd[rd.capa - 1]
     assert_equal 1, rd.incr(rd.capa - 1)
     assert_raises(ArgumentError) { rd[rd.capa] }
-    rescue RangeError
+  rescue RangeError
   end # if RUBY_PLATFORM =~ /linux/
 
   def test_evaporate
diff --git a/test/test_tcp_info.rb b/test/test_tcp_info.rb
index b107565..2ddacfd 100644
--- a/test/test_tcp_info.rb
+++ b/test/test_tcp_info.rb
@@ -60,10 +60,10 @@ class TestTCP_Info < Test::Unit::TestCase
     a = s.accept
     i = Raindrops::TCP_Info.new(a)
     assert i.last_data_recv >= delay_ms, "#{i.last_data_recv} < #{delay_ms}"
-    ensure
-      c.close if c
-      a.close if a
-      s.close
+  ensure
+    c.close if c
+    a.close if a
+    s.close
   end
 
   def test_tcp_server_state_closed
diff --git a/test/test_watcher.rb b/test/test_watcher.rb
index d1e4d15..28ac49b 100644
--- a/test/test_watcher.rb
+++ b/test/test_watcher.rb
@@ -118,28 +118,28 @@ class TestWatcher < Test::Unit::TestCase
 
   def test_x_current_header
     env = @req.class.env_for "/active/#@addr.txt"
-    status, headers, body = @app.call(env)
+    _status, headers, _body = @app.call(env)
     assert_equal "0", headers["X-Current"], headers.inspect
 
     env = @req.class.env_for "/queued/#@addr.txt"
-    status, headers, body = @app.call(env)
+    _status, headers, _body = @app.call(env)
     assert_equal "1", headers["X-Current"], headers.inspect
 
     @ios << @srv.accept
     sleep 0.1
 
     env = @req.class.env_for "/queued/#@addr.txt"
-    status, headers, body = @app.call(env)
+    _status, headers, _body = @app.call(env)
     assert_equal "0", headers["X-Current"], headers.inspect
 
     env = @req.class.env_for "/active/#@addr.txt"
-    status, headers, body = @app.call(env)
+    _status, headers, _body = @app.call(env)
     assert_equal "1", headers["X-Current"], headers.inspect
   end
 
   def test_peaks
     env = @req.class.env_for "/active/#@addr.txt"
-    status, headers, body = @app.call(env.dup)
+    _status, headers, _body = @app.call(env.dup)
     start = headers["X-First-Peak-At"]
     assert headers["X-First-Peak-At"], headers.inspect
     assert headers["X-Last-Peak-At"], headers.inspect
@@ -148,14 +148,14 @@ class TestWatcher < Test::Unit::TestCase
     before = headers["X-Last-Peak-At"]
 
     env = @req.class.env_for "/queued/#@addr.txt"
-    status, headers, body = @app.call(env)
+    _status, headers, _body = @app.call(env)
     assert_nothing_raised { Time.parse(headers["X-First-Peak-At"]) }
     assert_nothing_raised { Time.parse(headers["X-Last-Peak-At"]) }
     assert_equal before, headers["X-Last-Peak-At"], "should not change"
 
     sleep 2
     env = @req.class.env_for "/active/#@addr.txt"
-    status, headers, body = @app.call(env.dup)
+    _status, headers, _body = @app.call(env.dup)
     assert_equal before, headers["X-Last-Peak-At"], headers.inspect
 
     @ios << @srv.accept
@@ -167,7 +167,7 @@ class TestWatcher < Test::Unit::TestCase
     end
     sleep 0.1
     env = @req.class.env_for "/queued/#@addr.txt"
-    status, headers, body = @app.call(env.dup)
+    _status, headers, _body = @app.call(env.dup)
     assert headers["X-Last-Peak-At"], headers.inspect
     assert_nothing_raised { Time.parse(headers["X-Last-Peak-At"]) }
     assert before != headers["X-Last-Peak-At"]
@@ -177,7 +177,7 @@ class TestWatcher < Test::Unit::TestCase
     sleep 2
 
     env = @req.class.env_for "/queued/#@addr.txt"
-    status, headers, body = @app.call(env)
+    _status, headers, _body = @app.call(env)
     assert_equal "0", headers["X-Current"]
     assert_nothing_raised { Time.parse(headers["X-Last-Peak-At"]) }
     assert_equal queued_before, headers["X-Last-Peak-At"], "should not change"