Skip to content

Commit

Permalink
Use TIMEOUT constant instead of hardcoded 2 second sleep (#4952)
Browse files Browse the repository at this point in the history
* Use TIMEOUT constant instead of hardcoded 2 second sleep

* Add a test
  • Loading branch information
dzunk committed Aug 19, 2021
1 parent d69e3c6 commit 69b2aec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit 69b2aec

Please sign in to comment.