diff --git a/lib/sidekiq/util.rb b/lib/sidekiq/util.rb index ae867ab0..31789e5c 100644 --- a/lib/sidekiq/util.rb +++ b/lib/sidekiq/util.rb @@ -51,5 +51,18 @@ module Sidekiq end end + def want_a_hertz_donut? + # what's a hertz donut? + # punch! Hurts, don't it? + info = Sidekiq.redis {|c| c.info } + if info['connected_clients'].to_i > 1000 && info['hz'].to_i >= 10 + Sidekiq.logger.warn { "Your Redis `hz` setting is too high at #{info['hz']}. See mperham/sidekiq#2431. Set it to 3 in #{info[:config_file]}" } + true + else + Sidekiq.logger.debug { "Redis hz: #{info['hz']}. Client count: #{info['connected_clients']}" } + false + end + end + end end diff --git a/test/helper.rb b/test/helper.rb index 82baf09c..365acaaf 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -32,3 +32,17 @@ REDIS = Sidekiq::RedisConnection.create(:url => REDIS_URL, :namespace => 'testy' Sidekiq.configure_client do |config| config.redis = { :url => REDIS_URL, :namespace => 'testy' } end + +def capture_logging(lvl=Logger::INFO) + old = Sidekiq.logger + begin + out = StringIO.new + logger = Logger.new(out) + logger.level = lvl + Sidekiq.logger = logger + yield + out.string + ensure + Sidekiq.logger = old + end +end diff --git a/test/test_sidekiq.rb b/test/test_sidekiq.rb index dc2d32ce..21b76fc7 100644 --- a/test/test_sidekiq.rb +++ b/test/test_sidekiq.rb @@ -69,11 +69,15 @@ class TestSidekiq < Sidekiq::Test describe 'error handling' do it 'deals with user-specified error handlers which raise errors' do - Sidekiq.error_handlers << proc {|x, hash| - raise 'boom' - } - cli = Sidekiq::CLI.new - cli.handle_exception(RuntimeError.new("hello")) + output = capture_logging do + Sidekiq.error_handlers << proc {|x, hash| + raise 'boom' + } + cli = Sidekiq::CLI.new + cli.handle_exception(RuntimeError.new("hello")) + end + assert_includes output, "boom" + assert_includes output, "ERROR" end end end diff --git a/test/test_util.rb b/test/test_util.rb new file mode 100644 index 00000000..01e9e7fc --- /dev/null +++ b/test/test_util.rb @@ -0,0 +1,18 @@ +require_relative 'helper' +require 'sidekiq' +require 'sidekiq/web_helpers' + +class TestUtil < Sidekiq::Test + + class Helpers + include Sidekiq::Util + end + + def test_hertz_donut + obj = Helpers.new + output = capture_logging(Logger::DEBUG) do + assert_equal false, obj.want_a_hertz_donut? + end + assert_includes output, "hz: 10" + end +end