@@ -36,14 +36,7 @@ class ActiveSupport::TestCase
36
36
37
37
private
38
38
def wait_for_jobs_to_finish_for ( timeout = 1 . second )
39
- skip_active_record_query_cache do
40
- Timeout . timeout ( timeout ) do
41
- while SolidQueue ::Job . where ( finished_at : nil ) . any? do
42
- sleep 0.05
43
- end
44
- end
45
- end
46
- rescue Timeout ::Error
39
+ wait_while_with_timeout ( timeout ) { SolidQueue ::Job . where ( finished_at : nil ) . any? }
47
40
end
48
41
49
42
def assert_no_pending_jobs
@@ -59,12 +52,7 @@ def run_supervisor_as_fork(**options)
59
52
end
60
53
61
54
def wait_for_registered_processes ( count , timeout : 1 . second )
62
- Timeout . timeout ( timeout ) do
63
- while SolidQueue ::Process . count != count do
64
- sleep 0.05
65
- end
66
- end
67
- rescue Timeout ::Error
55
+ wait_while_with_timeout ( timeout ) { SolidQueue ::Process . count != count }
68
56
end
69
57
70
58
def assert_no_registered_processes
@@ -86,14 +74,27 @@ def terminate_process(pid, timeout: 10, signal: :TERM)
86
74
87
75
def wait_for_process_termination_with_timeout ( pid , timeout : 10 , exitstatus : 0 )
88
76
Timeout . timeout ( timeout ) do
89
- Process . waitpid ( pid )
90
- assert exitstatus , $?. exitstatus
77
+ if process_exists? ( pid )
78
+ Process . waitpid ( pid )
79
+ assert exitstatus , $?. exitstatus
80
+ end
91
81
end
92
82
rescue Timeout ::Error
93
83
signal_process ( pid , :KILL )
94
84
raise
95
85
end
96
86
87
+ def wait_while_with_timeout ( timeout , &block )
88
+ Timeout . timeout ( timeout ) do
89
+ skip_active_record_query_cache do
90
+ while block . call
91
+ sleep 0.05
92
+ end
93
+ end
94
+ end
95
+ rescue Timeout ::Error
96
+ end
97
+
97
98
def signal_process ( pid , signal , wait : nil )
98
99
Thread . new do
99
100
sleep ( wait ) if wait
0 commit comments