Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TIMEOUT constant instead of hardcoded 2 second sleep #4952

Merged
merged 2 commits into from Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sidekiq/fetch.rb
Expand Up @@ -40,7 +40,7 @@ def retrieve_work
# 4825 Sidekiq Pro with all queues paused will return an
# empty set of queues with a trailing TIMEOUT value.
if qs.size <= 1
sleep(2)
sleep(TIMEOUT)
return nil
end

Expand Down
7 changes: 7 additions & 0 deletions test/test_fetch.rb
Expand Up @@ -57,4 +57,11 @@
assert_equal 1, q2.size
end

it 'sleeps when no queues are active' do
fetch = Sidekiq::BasicFetch.new(:queues => [])
mock = Minitest::Mock.new
mock.expect(:call, nil, [Sidekiq::BasicFetch::TIMEOUT])
fetch.stub(:sleep, mock) { assert_nil fetch.retrieve_work }
mock.verify
end
end