mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Add helper method to encapsulate hz check, #2431
This commit is contained in:
parent
9f772406c4
commit
4433e685ba
4 changed files with 54 additions and 5 deletions
|
@ -51,5 +51,18 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,3 +32,17 @@ REDIS = Sidekiq::RedisConnection.create(:url => REDIS_URL, :namespace => 'testy'
|
||||||
Sidekiq.configure_client do |config|
|
Sidekiq.configure_client do |config|
|
||||||
config.redis = { :url => REDIS_URL, :namespace => 'testy' }
|
config.redis = { :url => REDIS_URL, :namespace => 'testy' }
|
||||||
end
|
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
|
||||||
|
|
|
@ -69,11 +69,15 @@ class TestSidekiq < Sidekiq::Test
|
||||||
|
|
||||||
describe 'error handling' do
|
describe 'error handling' do
|
||||||
it 'deals with user-specified error handlers which raise errors' do
|
it 'deals with user-specified error handlers which raise errors' do
|
||||||
|
output = capture_logging do
|
||||||
Sidekiq.error_handlers << proc {|x, hash|
|
Sidekiq.error_handlers << proc {|x, hash|
|
||||||
raise 'boom'
|
raise 'boom'
|
||||||
}
|
}
|
||||||
cli = Sidekiq::CLI.new
|
cli = Sidekiq::CLI.new
|
||||||
cli.handle_exception(RuntimeError.new("hello"))
|
cli.handle_exception(RuntimeError.new("hello"))
|
||||||
end
|
end
|
||||||
|
assert_includes output, "boom"
|
||||||
|
assert_includes output, "ERROR"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
18
test/test_util.rb
Normal file
18
test/test_util.rb
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue