diff --git a/test/integration/forked_processes_lifecycle_test.rb b/test/integration/forked_processes_lifecycle_test.rb index e0e8b245..d4834a70 100644 --- a/test/integration/forked_processes_lifecycle_test.rb +++ b/test/integration/forked_processes_lifecycle_test.rb @@ -266,8 +266,7 @@ class ForkedProcessesLifecycleTest < ActiveSupport::TestCase private def assert_clean_termination - wait_for_registered_processes 0, timeout: 0.2.second - assert_no_registered_processes + wait_for_full_process_shutdown assert_no_claimed_jobs assert_not process_exists?(@pid) end diff --git a/test/integration/puma/plugin_testing.rb b/test/integration/puma/plugin_testing.rb index 0cb82095..d8369d62 100644 --- a/test/integration/puma/plugin_testing.rb +++ b/test/integration/puma/plugin_testing.rb @@ -31,8 +31,6 @@ module PluginTesting teardown do terminate_process(@pid, signal: :INT) if process_exists?(@pid) - - wait_for_registered_processes 0, timeout: 2.seconds end end diff --git a/test/test_helpers/processes_test_helper.rb b/test/test_helpers/processes_test_helper.rb index 3e857d36..c59ed75e 100644 --- a/test/test_helpers/processes_test_helper.rb +++ b/test/test_helpers/processes_test_helper.rb @@ -7,8 +7,15 @@ def run_supervisor_as_fork(**options) end end + def wait_for_full_process_shutdown + wait_for_registered_processes(0, timeout: SolidQueue.shutdown_timeout + 0.2.seconds) + assert_no_registered_processes + end + def wait_for_registered_processes(count, timeout: 1.second) - wait_while_with_timeout(timeout) { SolidQueue::Process.count != count } + wait_while_with_timeout(timeout) do + SolidQueue::Process.count != count + end end def assert_no_registered_processes diff --git a/test/unit/async_supervisor_test.rb b/test/unit/async_supervisor_test.rb index b6dd2db1..171a399e 100644 --- a/test/unit/async_supervisor_test.rb +++ b/test/unit/async_supervisor_test.rb @@ -10,8 +10,7 @@ class AsyncSupervisorTest < ActiveSupport::TestCase assert_registered_processes(kind: "Dispatcher", supervisor_id: supervisor.process_id) supervisor.stop - - assert_no_registered_processes + wait_for_full_process_shutdown end test "start with provided configuration" do @@ -24,8 +23,7 @@ class AsyncSupervisorTest < ActiveSupport::TestCase assert_registered_processes(kind: "Dispatcher", supervisor_id: supervisor.process_id) supervisor.stop - - assert_no_registered_processes + wait_for_full_process_shutdown end test "failed orphaned executions" do @@ -52,6 +50,7 @@ class AsyncSupervisorTest < ActiveSupport::TestCase assert_registered_processes(kind: "Supervisor(async)") supervisor.stop + wait_for_full_process_shutdown assert_equal 0, SolidQueue::ClaimedExecution.count assert_equal 3, SolidQueue::FailedExecution.count diff --git a/test/unit/dispatcher_test.rb b/test/unit/dispatcher_test.rb index 6332fa98..f1d5e442 100644 --- a/test/unit/dispatcher_test.rb +++ b/test/unit/dispatcher_test.rb @@ -12,6 +12,7 @@ class DispatcherTest < ActiveSupport::TestCase teardown do @dispatcher.stop + wait_for_full_process_shutdown end test "dispatcher is registered as process" do @@ -57,7 +58,8 @@ class DispatcherTest < ActiveSupport::TestCase with_active_record_logger(ActiveSupport::Logger.new(log)) do with_polling(silence: false) do @dispatcher.start - sleep 0.2 + wait_for_registered_processes(1, timeout: 1.second) + sleep(0.3) end end @@ -69,7 +71,8 @@ class DispatcherTest < ActiveSupport::TestCase with_active_record_logger(ActiveSupport::Logger.new(log)) do with_polling(silence: true) do @dispatcher.start - sleep 0.2 + wait_for_registered_processes(1, timeout: 1.second) + sleep(0.3) end end @@ -80,13 +83,10 @@ class DispatcherTest < ActiveSupport::TestCase with_active_record_logger(nil) do with_polling(silence: true) do @dispatcher.start - sleep 0.2 + wait_for_registered_processes(1, timeout: 1.second) + sleep 0.3 end end - - @dispatcher.stop - wait_for_registered_processes(0, timeout: 1.second) - assert_no_registered_processes end test "run more than one instance of the dispatcher without recurring tasks" do @@ -100,7 +100,7 @@ class DispatcherTest < ActiveSupport::TestCase @dispatcher.start another_dispatcher.start - wait_while_with_timeout(1.second) { SolidQueue::ScheduledExecution.any? } + wait_while_with_timeout(2.second) { SolidQueue::ScheduledExecution.any? } assert_equal 0, SolidQueue::ScheduledExecution.count assert_equal 15, SolidQueue::ReadyExecution.count @@ -115,8 +115,11 @@ class DispatcherTest < ActiveSupport::TestCase end dispatchers.each(&:start) - sleep 2 + wait_for_registered_processes(2, timeout: 2.second) + sleep 1.5 + dispatchers.each(&:stop) + wait_for_full_process_shutdown assert_equal SolidQueue::Job.count, SolidQueue::RecurringExecution.count run_at_times = SolidQueue::RecurringExecution.all.map(&:run_at).sort diff --git a/test/unit/fork_supervisor_test.rb b/test/unit/fork_supervisor_test.rb index 30d4c3db..7abc40ff 100644 --- a/test/unit/fork_supervisor_test.rb +++ b/test/unit/fork_supervisor_test.rb @@ -87,7 +87,7 @@ class ForkSupervisorTest < ActiveSupport::TestCase assert File.exist?(@pidfile) assert_equal pid, File.read(@pidfile).strip.to_i - wait_for_registered_processes(0) + wait_for_full_process_shutdown pid = run_supervisor_as_fork wait_for_registered_processes(4) diff --git a/test/unit/worker_test.rb b/test/unit/worker_test.rb index 36f67bb0..7fadef6f 100644 --- a/test/unit/worker_test.rb +++ b/test/unit/worker_test.rb @@ -118,8 +118,7 @@ class WorkerTest < ActiveSupport::TestCase end @worker.stop - wait_for_registered_processes(0, timeout: 1.second) - assert_no_registered_processes + wait_for_full_process_shutdown end test "run inline" do