@@ -12,7 +12,6 @@ class DispatcherTest < ActiveSupport::TestCase
1212
1313 teardown do
1414 @dispatcher . stop
15- wait_for_registered_processes ( 0 , timeout : 2 . seconds )
1615 end
1716
1817 test "dispatcher is registered as process" do
@@ -76,52 +75,59 @@ class DispatcherTest < ActiveSupport::TestCase
7675 assert_no_registered_processes
7776 end
7877
79- test "dispatch scheduled executions" do
80- skip_active_record_query_cache do
81- 15 . times do
82- AddToBufferJob . set ( wait : 0.5 . second ) . perform_later ( "I'm scheduled" )
83- end
84- sleep 0.5 . second
85- assert_equal 15 , SolidQueue ::ScheduledExecution . count
78+ test "run more than one instance of the dispatcher" do
79+ 15 . times do
80+ AddToBufferJob . set ( wait : 0.5 . second ) . perform_later ( "I'm scheduled" )
81+ end
82+ sleep 0.5 . second
83+ assert_equal 15 , SolidQueue ::ScheduledExecution . count
8684
87- @dispatcher . start
88- wait_for_registered_processes ( 1 , timeout : 2 . seconds )
85+ another_dispatcher = SolidQueue ::Dispatcher . new ( polling_interval : 0.1 , batch_size : 10 )
8986
90- wait_while_with_timeout ( 3 . seconds ) { SolidQueue ::ScheduledExecution . any? }
87+ @dispatcher . start
88+ another_dispatcher . start
89+
90+ wait_while_with_timeout ( 1 . second ) { SolidQueue ::ScheduledExecution . any? }
9191
92+ skip_active_record_query_cache do
9293 assert_equal 0 , SolidQueue ::ScheduledExecution . count
9394 assert_equal 15 , SolidQueue ::ReadyExecution . count
9495 end
96+ ensure
97+ another_dispatcher &.stop
9598 end
9699
97100 test "sleeps `0.seconds` between polls if there are ready to dispatch jobs" do
98- skip_active_record_query_cache do
99- @dispatcher = SolidQueue ::Dispatcher . new ( polling_interval : 10 , batch_size : 1 )
100- @dispatcher . expects ( :interruptible_sleep ) . with ( 0 . seconds ) . at_least ( 3 )
101- @dispatcher . expects ( :interruptible_sleep ) . with ( @dispatcher . polling_interval ) . at_least_once
102- @dispatcher . expects ( :handle_thread_error ) . never
101+ dispatcher = SolidQueue ::Dispatcher . new ( polling_interval : 10 , batch_size : 1 )
102+ dispatcher . expects ( :interruptible_sleep ) . with ( 0 . seconds ) . at_least ( 3 )
103+ dispatcher . expects ( :interruptible_sleep ) . with ( dispatcher . polling_interval ) . at_least_once
104+ dispatcher . expects ( :handle_thread_error ) . never
103105
104- 3 . times { AddToBufferJob . set ( wait : 0.5 . second ) . perform_later ( "I'm scheduled" ) }
105- sleep 0.5 . second
106- assert_equal 3 , SolidQueue ::ScheduledExecution . count
106+ 3 . times { AddToBufferJob . set ( wait : 0.5 . second ) . perform_later ( "I'm scheduled" ) }
107+ sleep 0.5 . second
108+ assert_equal 3 , SolidQueue ::ScheduledExecution . count
107109
108- @dispatcher . start
109- wait_for_registered_processes ( 1 , timeout : 2 . seconds )
110- wait_while_with_timeout ( 3 . seconds ) { SolidQueue ::ScheduledExecution . any? }
110+ dispatcher . start
111+ wait_while_with_timeout ( 1 . second ) { SolidQueue ::ScheduledExecution . any? }
111112
113+ skip_active_record_query_cache do
112114 assert_equal 0 , SolidQueue ::ScheduledExecution . count
113115 assert_equal 3 , SolidQueue ::ReadyExecution . count
114116 end
117+ ensure
118+ dispatcher . stop
115119 end
116120
117121 test "sleeps `polling_interval` between polls if there are no un-dispatched jobs" do
118- @ dispatcher = SolidQueue ::Dispatcher . new ( polling_interval : 10 , batch_size : 1 )
119- @ dispatcher. expects ( :interruptible_sleep ) . with ( 0 . seconds ) . never
120- @ dispatcher. expects ( :interruptible_sleep ) . with ( @ dispatcher. polling_interval ) . at_least_once
121- @ dispatcher. expects ( :handle_thread_error ) . never
122+ dispatcher = SolidQueue ::Dispatcher . new ( polling_interval : 10 , batch_size : 1 )
123+ dispatcher . expects ( :interruptible_sleep ) . with ( 0 . seconds ) . never
124+ dispatcher . expects ( :interruptible_sleep ) . with ( dispatcher . polling_interval ) . at_least_once
125+ dispatcher . expects ( :handle_thread_error ) . never
122126
123- @ dispatcher. start
127+ dispatcher . start
124128 wait_while_with_timeout ( 1 . second ) { !SolidQueue ::ScheduledExecution . exists? }
129+ ensure
130+ dispatcher . stop
125131 end
126132
127133 private
0 commit comments