From f99a7568e03bb31c68e68659d7aebd93a27d3028 Mon Sep 17 00:00:00 2001 From: Pedro Mendes Date: Mon, 17 Nov 2025 12:01:10 -0300 Subject: [PATCH 1/2] Attempt to reduce flakiness of `recurring_tasks_test` --- test/integration/recurring_tasks_test.rb | 43 +++++++++++++----------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/test/integration/recurring_tasks_test.rb b/test/integration/recurring_tasks_test.rb index 7367bc06..e8c71104 100644 --- a/test/integration/recurring_tasks_test.rb +++ b/test/integration/recurring_tasks_test.rb @@ -6,26 +6,17 @@ class RecurringTasksTest < ActiveSupport::TestCase self.use_transactional_tests = false setup do - @pid = run_supervisor_as_fork(skip_recurring: false) - # 1 supervisor + 2 workers + 1 dispatcher + 1 scheduler - wait_for_registered_processes(5, timeout: 3.second) + @pid = run_recurring_supervisor end teardown do - terminate_process(@pid) if process_exists?(@pid) - - SolidQueue::Process.destroy_all - SolidQueue::Job.destroy_all - SolidQueue::RecurringTask.delete_all - JobResult.delete_all + terminate_gracefully(@pid) end test "enqueue and process periodic tasks" do wait_for_jobs_to_be_enqueued(2, timeout: 2.5.seconds) wait_for_jobs_to_finish_for(2.5.seconds) - terminate_process(@pid) - skip_active_record_query_cache do assert SolidQueue::Job.count >= 2 SolidQueue::Job.all.each do |job| @@ -39,24 +30,20 @@ class RecurringTasksTest < ActiveSupport::TestCase assert_equal "42", result.value end end + + # no need to stop @pid supervisor - that will be handled in teardown end test "persist and delete configured tasks" do configured_task = { periodic_store_result: { class: "StoreResultJob", schedule: "every second" } } - # Wait for concurrency schedule loading after process registration - sleep(0.5) assert_recurring_tasks configured_task - terminate_process(@pid) - task = SolidQueue::RecurringTask.find_by(key: "periodic_store_result") task.update!(class_name: "StoreResultJob", schedule: "every minute", arguments: [ 42 ]) - @pid = run_supervisor_as_fork(skip_recurring: false) - wait_for_registered_processes(5, timeout: 3.second) + terminate_gracefully(@pid) - # Wait for concurrency schedule loading after process registration - sleep(0.5) + @pid = run_recurring_supervisor assert_recurring_tasks configured_task @@ -72,9 +59,10 @@ class RecurringTasksTest < ActiveSupport::TestCase assert_recurring_tasks updated_task - terminate_process(@pid) scheduler1.stop scheduler2.stop + + # no need to stop @pid supervisor - that will be handled in teardown end private @@ -92,4 +80,19 @@ def assert_recurring_tasks(expected_tasks) end end end + + def run_recurring_supervisor + pid = run_supervisor_as_fork(skip_recurring: false) + wait_for_registered_processes(5, timeout: 3.seconds) # 1 supervisor + 2 workers + 1 dispatcher + 1 scheduler + sleep 1.second # Wait for concurrency schedule loading after process registration + pid + end + + def terminate_gracefully(pid) + return if pid.nil? || !process_exists?(pid) + + terminate_process(pid) + wait_for_registered_processes(0, timeout: SolidQueue.shutdown_timeout) + sleep SolidQueue.shutdown_timeout + end end From 532d719478fa1582dbc6b98791f147c71a35512a Mon Sep 17 00:00:00 2001 From: Pedro Mendes Date: Mon, 17 Nov 2025 12:57:33 -0300 Subject: [PATCH 2/2] Removing comments && extra sleep --- test/integration/recurring_tasks_test.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/integration/recurring_tasks_test.rb b/test/integration/recurring_tasks_test.rb index e8c71104..b50e61c3 100644 --- a/test/integration/recurring_tasks_test.rb +++ b/test/integration/recurring_tasks_test.rb @@ -30,8 +30,6 @@ class RecurringTasksTest < ActiveSupport::TestCase assert_equal "42", result.value end end - - # no need to stop @pid supervisor - that will be handled in teardown end test "persist and delete configured tasks" do @@ -61,8 +59,6 @@ class RecurringTasksTest < ActiveSupport::TestCase scheduler1.stop scheduler2.stop - - # no need to stop @pid supervisor - that will be handled in teardown end private @@ -93,6 +89,5 @@ def terminate_gracefully(pid) terminate_process(pid) wait_for_registered_processes(0, timeout: SolidQueue.shutdown_timeout) - sleep SolidQueue.shutdown_timeout end end