raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <bofh@yhbt.net>
To: raindrops-public@yhbt.net
Subject: [PATCH 2/3] fixes for newer rubies
Date: Mon,  6 Jan 2020 09:54:50 +0000	[thread overview]
Message-ID: <20200106095451.550-3-bofh@yhbt.net> (raw)
In-Reply-To: <20200106095451.550-1-bofh@yhbt.net>

Newer rubies have more warnings
---
 examples/linux-listener-stats.rb             |  3 +--
 lib/raindrops/aggregate/pmq.rb               | 12 ++++++------
 lib/raindrops/linux.rb                       |  9 ++++-----
 test/ipv6_enabled.rb                         |  8 ++++----
 test/test_linux.rb                           |  5 +++--
 test/test_linux_all_tcp_listen_stats_leak.rb |  4 ++--
 test/test_raindrops.rb                       |  2 +-
 test/test_tcp_info.rb                        |  8 ++++----
 test/test_watcher.rb                         | 18 +++++++++---------
 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 @@
 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 @@
   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 @@ def master_loop
       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 @@ def flush_master
   # 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 @@ def unix_listener_stats(paths = nil)
     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 @@ def unix_listener_stats(paths = nil)
     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 @@ def test_unix_all_unused
 
     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 @@ def test_tcp_reuse_sock
     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 @@ def test_leak
     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 @@ def test_resize_mremap
     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 @@ def test_tcp_server_delayed
     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 @@ def test_tail_queued_min
 
   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 @@ def test_peaks
     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 @@ def test_peaks
     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 @@ def test_peaks
     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"

  parent reply	other threads:[~2020-01-06  9:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-06  9:54 [PATCH 0/3] misc fixes and a new home Eric Wong
2020-01-06  9:54 ` [PATCH 1/3] ext/raindrops/extconf: fix cflags reset on ancient CC Eric Wong
2020-01-06  9:54 ` Eric Wong [this message]
2020-01-06  9:54 ` [PATCH 3/3] replace bogomips.org with yhbt.net Eric Wong
2020-01-06 10:17   ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/raindrops/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200106095451.550-3-bofh@yhbt.net \
    --to=bofh@yhbt.net \
    --cc=raindrops-public@yhbt.net \
    --subject='Re: [PATCH 2/3] fixes for newer rubies' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	../../raindrops.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).