diff --git a/test/unit/dispatcher_test.rb b/test/unit/dispatcher_test.rb index 7df0591f..9ce720c2 100644 --- a/test/unit/dispatcher_test.rb +++ b/test/unit/dispatcher_test.rb @@ -38,15 +38,17 @@ class DispatcherTest < ActiveSupport::TestCase test "polling queries are logged" do log = StringIO.new + polling_query = /SELECT .* FROM .solid_queue_scheduled_executions. WHERE/ + with_active_record_logger(ActiveSupport::Logger.new(log)) do with_polling(silence: false) do rewind_io(log) @dispatcher.start - sleep 0.5.second + wait_while_with_timeout(3.seconds) { !log.string.match?(polling_query) } end end - assert_match /SELECT .* FROM .solid_queue_scheduled_executions. WHERE/, log.string + assert_match polling_query, log.string end test "polling queries can be silenced" do @@ -108,7 +110,9 @@ class DispatcherTest < ActiveSupport::TestCase assert_equal 3, SolidQueue::ScheduledExecution.count dispatcher.start - wait_while_with_timeout(1.second) { SolidQueue::ScheduledExecution.any? } + # Give the dispatcher thread enough margin to boot and run its first polls + # on a slow runner; the wait returns as soon as everything is dispatched. + wait_while_with_timeout(5.seconds) { SolidQueue::ScheduledExecution.any? } skip_active_record_query_cache do assert_equal 0, SolidQueue::ScheduledExecution.count diff --git a/test/unit/worker_test.rb b/test/unit/worker_test.rb index c21cd574..8907d916 100644 --- a/test/unit/worker_test.rb +++ b/test/unit/worker_test.rb @@ -146,14 +146,16 @@ class WorkerTest < ActiveSupport::TestCase test "polling queries are logged" do log = StringIO.new + polling_query = /SELECT .* FROM .solid_queue_ready_executions. WHERE .solid_queue_ready_executions...queue_name./ + with_active_record_logger(ActiveSupport::Logger.new(log)) do with_polling(silence: false) do @worker.start - sleep 0.2 + wait_while_with_timeout(3.seconds) { !log.string.match?(polling_query) } end end - assert_match /SELECT .* FROM .solid_queue_ready_executions. WHERE .solid_queue_ready_executions...queue_name./, log.string + assert_match polling_query, log.string end test "polling queries can be silenced" do