@@ -6,26 +6,17 @@ class RecurringTasksTest < ActiveSupport::TestCase
66 self . use_transactional_tests = false
77
88 setup do
9- @pid = run_supervisor_as_fork ( skip_recurring : false )
10- # 1 supervisor + 2 workers + 1 dispatcher + 1 scheduler
11- wait_for_registered_processes ( 5 , timeout : 3 . second )
9+ @pid = run_recurring_supervisor
1210 end
1311
1412 teardown do
15- terminate_process ( @pid ) if process_exists? ( @pid )
16-
17- SolidQueue ::Process . destroy_all
18- SolidQueue ::Job . destroy_all
19- SolidQueue ::RecurringTask . delete_all
20- JobResult . delete_all
13+ terminate_gracefully ( @pid )
2114 end
2215
2316 test "enqueue and process periodic tasks" do
2417 wait_for_jobs_to_be_enqueued ( 2 , timeout : 2.5 . seconds )
2518 wait_for_jobs_to_finish_for ( 2.5 . seconds )
2619
27- terminate_process ( @pid )
28-
2920 skip_active_record_query_cache do
3021 assert SolidQueue ::Job . count >= 2
3122 SolidQueue ::Job . all . each do |job |
@@ -39,24 +30,20 @@ class RecurringTasksTest < ActiveSupport::TestCase
3930 assert_equal "42" , result . value
4031 end
4132 end
33+
34+ # no need to stop @pid supervisor - that will be handled in teardown
4235 end
4336
4437 test "persist and delete configured tasks" do
4538 configured_task = { periodic_store_result : { class : "StoreResultJob" , schedule : "every second" } }
46- # Wait for concurrency schedule loading after process registration
47- sleep ( 0.5 )
4839
4940 assert_recurring_tasks configured_task
50- terminate_process ( @pid )
51-
5241 task = SolidQueue ::RecurringTask . find_by ( key : "periodic_store_result" )
5342 task . update! ( class_name : "StoreResultJob" , schedule : "every minute" , arguments : [ 42 ] )
5443
55- @pid = run_supervisor_as_fork ( skip_recurring : false )
56- wait_for_registered_processes ( 5 , timeout : 3 . second )
44+ terminate_gracefully ( @pid )
5745
58- # Wait for concurrency schedule loading after process registration
59- sleep ( 0.5 )
46+ @pid = run_recurring_supervisor
6047
6148 assert_recurring_tasks configured_task
6249
@@ -72,9 +59,10 @@ class RecurringTasksTest < ActiveSupport::TestCase
7259
7360 assert_recurring_tasks updated_task
7461
75- terminate_process ( @pid )
7662 scheduler1 . stop
7763 scheduler2 . stop
64+
65+ # no need to stop @pid supervisor - that will be handled in teardown
7866 end
7967
8068 private
@@ -92,4 +80,19 @@ def assert_recurring_tasks(expected_tasks)
9280 end
9381 end
9482 end
83+
84+ def run_recurring_supervisor
85+ pid = run_supervisor_as_fork ( skip_recurring : false )
86+ wait_for_registered_processes ( 5 , timeout : 3 . seconds ) # 1 supervisor + 2 workers + 1 dispatcher + 1 scheduler
87+ sleep 1 . second # Wait for concurrency schedule loading after process registration
88+ pid
89+ end
90+
91+ def terminate_gracefully ( pid )
92+ return if pid . nil? || !process_exists? ( pid )
93+
94+ terminate_process ( pid )
95+ wait_for_registered_processes ( 0 , timeout : SolidQueue . shutdown_timeout )
96+ sleep SolidQueue . shutdown_timeout
97+ end
9598end
0 commit comments