@@ -12,22 +12,30 @@ class LifecycleHooksTest < ActiveSupport::TestCase
12
12
SolidQueue . on_worker_start { JobResult . create! ( status : :hook_called , value : :worker_start ) }
13
13
SolidQueue . on_worker_stop { JobResult . create! ( status : :hook_called , value : :worker_stop ) }
14
14
15
- pid = run_supervisor_as_fork ( workers : [ { queues : "*" } ] )
15
+ SolidQueue . on_dispatcher_start { JobResult . create! ( status : :hook_called , value : :dispatcher_start ) }
16
+ SolidQueue . on_dispatcher_stop { JobResult . create! ( status : :hook_called , value : :dispatcher_stop ) }
17
+
18
+ SolidQueue . on_scheduler_start { JobResult . create! ( status : :hook_called , value : :scheduler_start ) }
19
+ SolidQueue . on_scheduler_stop { JobResult . create! ( status : :hook_called , value : :scheduler_stop ) }
20
+
21
+ pid = run_supervisor_as_fork ( workers : [ { queues : "*" } ] , dispatchers : [ { batch_size : 100 } ] , skip_recurring : false )
16
22
wait_for_registered_processes ( 4 )
17
23
18
24
terminate_process ( pid )
19
25
wait_for_registered_processes ( 0 )
20
26
21
27
results = skip_active_record_query_cache do
22
- assert_equal 4 , JobResult . count
23
- JobResult . last ( 4 )
28
+ assert_equal 8 , JobResult . count
29
+ JobResult . last ( 8 )
24
30
end
25
31
26
- assert_equal "hook_called" , results . map ( &:status ) . first
27
- assert_equal [ " start" , " stop" , " worker_start" , " worker_stop" ] , results . map ( &:value ) . sort
32
+ assert_equal ( { "hook_called" => 8 } , results . map ( &:status ) . tally )
33
+ assert_equal %w[ start stop worker_start worker_stop dispatcher_start dispatcher_stop scheduler_start scheduler_stop ] . sort , results . map ( &:value ) . sort
28
34
ensure
29
35
SolidQueue ::Supervisor . clear_hooks
30
36
SolidQueue ::Worker . clear_hooks
37
+ SolidQueue ::Dispatcher . clear_hooks
38
+ SolidQueue ::Scheduler . clear_hooks
31
39
end
32
40
33
41
test "handle errors on lifecycle hooks" do
@@ -48,5 +56,7 @@ class LifecycleHooksTest < ActiveSupport::TestCase
48
56
SolidQueue . on_thread_error = previous_on_thread_error
49
57
SolidQueue ::Supervisor . clear_hooks
50
58
SolidQueue ::Worker . clear_hooks
59
+ SolidQueue ::Dispatcher . clear_hooks
60
+ SolidQueue ::Scheduler . clear_hooks
51
61
end
52
62
end
0 commit comments