From 8b5f383e6524e581b38edcf7744c122b075456ff Mon Sep 17 00:00:00 2001 From: wintan1418 Date: Thu, 30 Jul 2026 12:24:04 +0100 Subject: [PATCH 1/2] Wait for polling queries in logging tests instead of sleeping The "polling queries are logged" tests started a worker/dispatcher and slept for a fixed window before asserting the polling SELECT showed up in the log. On a slow CI runner, process boot (registration, pool startup) can eat the whole window before the first poll runs, failing the test. Poll the captured log for the expected query with a timeout instead: as fast as before in the common case, and robust when the runner is slow. Related to rails/solid_queue#602 --- test/unit/dispatcher_test.rb | 6 ++++-- test/unit/worker_test.rb | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/unit/dispatcher_test.rb b/test/unit/dispatcher_test.rb index 7df0591f5..8bf851472 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 diff --git a/test/unit/worker_test.rb b/test/unit/worker_test.rb index c21cd5741..8907d9163 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 From 521644bb5a460dcead27948c0f153fabdecdf6bf Mon Sep 17 00:00:00 2001 From: wintan1418 Date: Fri, 31 Jul 2026 14:45:35 +0100 Subject: [PATCH 2/2] Give the dispatcher time to boot in the zero-sleep polling test "sleeps 0.seconds between polls" started the dispatcher and waited only 1 second (without raising) for all three scheduled jobs to be dispatched. On a slow CI runner the dispatcher thread may not have booted and polled within that window, so the test failed on the scheduled executions count with all three jobs still there. Wait up to 5 seconds instead; the wait returns as soon as the jobs are dispatched, so the test's runtime is unchanged in the common case. --- test/unit/dispatcher_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/dispatcher_test.rb b/test/unit/dispatcher_test.rb index 8bf851472..9ce720c26 100644 --- a/test/unit/dispatcher_test.rb +++ b/test/unit/dispatcher_test.rb @@ -110,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