Skip to content

Commit 72da568

Browse files
committed
Improve waiting for full process shutdown in tests
1 parent 4afc5d1 commit 72da568

7 files changed

+26
-21
lines changed

Diff for: test/integration/forked_processes_lifecycle_test.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ class ForkedProcessesLifecycleTest < ActiveSupport::TestCase
266266

267267
private
268268
def assert_clean_termination
269-
wait_for_registered_processes 0, timeout: 0.2.second
270-
assert_no_registered_processes
269+
wait_for_full_process_shutdown
271270
assert_no_claimed_jobs
272271
assert_not process_exists?(@pid)
273272
end

Diff for: test/integration/puma/plugin_testing.rb

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ module PluginTesting
3131

3232
teardown do
3333
terminate_process(@pid, signal: :INT) if process_exists?(@pid)
34-
35-
wait_for_registered_processes 0, timeout: 2.seconds
3634
end
3735
end
3836

Diff for: test/test_helpers/processes_test_helper.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ def run_supervisor_as_fork(**options)
77
end
88
end
99

10+
def wait_for_full_process_shutdown
11+
wait_for_registered_processes(0, timeout: SolidQueue.shutdown_timeout + 0.2.seconds)
12+
assert_no_registered_processes
13+
end
14+
1015
def wait_for_registered_processes(count, timeout: 1.second)
11-
wait_while_with_timeout(timeout) { SolidQueue::Process.count != count }
16+
wait_while_with_timeout(timeout) do
17+
SolidQueue::Process.count != count
18+
end
1219
end
1320

1421
def assert_no_registered_processes

Diff for: test/unit/async_supervisor_test.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ class AsyncSupervisorTest < ActiveSupport::TestCase
1010
assert_registered_processes(kind: "Dispatcher", supervisor_id: supervisor.process_id)
1111

1212
supervisor.stop
13-
14-
assert_no_registered_processes
13+
wait_for_full_process_shutdown
1514
end
1615

1716
test "start with provided configuration" do
@@ -24,8 +23,7 @@ class AsyncSupervisorTest < ActiveSupport::TestCase
2423
assert_registered_processes(kind: "Dispatcher", supervisor_id: supervisor.process_id)
2524

2625
supervisor.stop
27-
28-
assert_no_registered_processes
26+
wait_for_full_process_shutdown
2927
end
3028

3129
test "failed orphaned executions" do
@@ -52,6 +50,7 @@ class AsyncSupervisorTest < ActiveSupport::TestCase
5250
assert_registered_processes(kind: "Supervisor(async)")
5351

5452
supervisor.stop
53+
wait_for_full_process_shutdown
5554

5655
assert_equal 0, SolidQueue::ClaimedExecution.count
5756
assert_equal 3, SolidQueue::FailedExecution.count

Diff for: test/unit/dispatcher_test.rb

+12-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class DispatcherTest < ActiveSupport::TestCase
1212

1313
teardown do
1414
@dispatcher.stop
15+
wait_for_full_process_shutdown
1516
end
1617

1718
test "dispatcher is registered as process" do
@@ -57,7 +58,8 @@ class DispatcherTest < ActiveSupport::TestCase
5758
with_active_record_logger(ActiveSupport::Logger.new(log)) do
5859
with_polling(silence: false) do
5960
@dispatcher.start
60-
sleep 0.2
61+
wait_for_registered_processes(1, timeout: 1.second)
62+
sleep(0.3)
6163
end
6264
end
6365

@@ -69,7 +71,8 @@ class DispatcherTest < ActiveSupport::TestCase
6971
with_active_record_logger(ActiveSupport::Logger.new(log)) do
7072
with_polling(silence: true) do
7173
@dispatcher.start
72-
sleep 0.2
74+
wait_for_registered_processes(1, timeout: 1.second)
75+
sleep(0.3)
7376
end
7477
end
7578

@@ -80,13 +83,10 @@ class DispatcherTest < ActiveSupport::TestCase
8083
with_active_record_logger(nil) do
8184
with_polling(silence: true) do
8285
@dispatcher.start
83-
sleep 0.2
86+
wait_for_registered_processes(1, timeout: 1.second)
87+
sleep 0.3
8488
end
8589
end
86-
87-
@dispatcher.stop
88-
wait_for_registered_processes(0, timeout: 1.second)
89-
assert_no_registered_processes
9090
end
9191

9292
test "run more than one instance of the dispatcher without recurring tasks" do
@@ -100,7 +100,7 @@ class DispatcherTest < ActiveSupport::TestCase
100100
@dispatcher.start
101101
another_dispatcher.start
102102

103-
wait_while_with_timeout(1.second) { SolidQueue::ScheduledExecution.any? }
103+
wait_while_with_timeout(2.second) { SolidQueue::ScheduledExecution.any? }
104104

105105
assert_equal 0, SolidQueue::ScheduledExecution.count
106106
assert_equal 15, SolidQueue::ReadyExecution.count
@@ -115,8 +115,11 @@ class DispatcherTest < ActiveSupport::TestCase
115115
end
116116

117117
dispatchers.each(&:start)
118-
sleep 2
118+
wait_for_registered_processes(2, timeout: 2.second)
119+
sleep 1.5
120+
119121
dispatchers.each(&:stop)
122+
wait_for_full_process_shutdown
120123

121124
assert_equal SolidQueue::Job.count, SolidQueue::RecurringExecution.count
122125
run_at_times = SolidQueue::RecurringExecution.all.map(&:run_at).sort

Diff for: test/unit/fork_supervisor_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class ForkSupervisorTest < ActiveSupport::TestCase
8787
assert File.exist?(@pidfile)
8888
assert_equal pid, File.read(@pidfile).strip.to_i
8989

90-
wait_for_registered_processes(0)
90+
wait_for_full_process_shutdown
9191

9292
pid = run_supervisor_as_fork
9393
wait_for_registered_processes(4)

Diff for: test/unit/worker_test.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ class WorkerTest < ActiveSupport::TestCase
118118
end
119119

120120
@worker.stop
121-
wait_for_registered_processes(0, timeout: 1.second)
122-
assert_no_registered_processes
121+
wait_for_full_process_shutdown
123122
end
124123

125124
test "run inline" do

0 commit comments

Comments
 (0)