Skip to content

Commit

Permalink
test: Allow leeway to avoid failing on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
  • Loading branch information
daipom authored and ashie committed Jun 9, 2022
1 parent bc0984f commit bf88f9a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions spec/multi_spawn_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
m.send_stop(true)
end

sleep(3)

monitors.count { |m| m.alive? }.should == workers
# On Windows, it takes some time to stop all multiple processes, so allow leeway to judge.
-> {
Timeout.timeout(5) do
sleep(0.5) until monitors.count { |m| m.alive? } == workers
end
}.should_not raise_error, "Not all workers restarted correctly."
ensure
server.stop(true)
t.join
Expand Down Expand Up @@ -91,7 +94,7 @@
end

# Wait for all workers to stop
Timeout.timeout(3) do
Timeout.timeout(5) do
sleep(0.5) until monitors.count { |m| m && m.alive? } == 0
end

Expand All @@ -100,12 +103,16 @@
mergin_time = 3

Timecop.freeze(Time.now + restart_worker_interval - mergin_time)
sleep(1)
sleep(1.5)
monitors.count { |m| m.alive? }.should == 0

Timecop.freeze(Time.now + 2 * mergin_time)
sleep(1)
monitors.count { |m| m.alive? }.should == workers
# On Windows, it takes some time to stop all multiple processes, so allow leeway to judge.
-> {
Timeout.timeout(5) do
sleep(0.5) until monitors.count { |m| m.alive? } == workers
end
}.should_not raise_error, "Not all workers restarted correctly."
ensure
server.stop(true)
t.join
Expand Down Expand Up @@ -172,7 +179,7 @@
end

# Wait for all workers to stop
Timeout.timeout(3) do
Timeout.timeout(5) do
sleep(0.5) until monitors.count { |m| m && m.alive? } == 0
end

Expand All @@ -181,11 +188,11 @@
mergin_time = 3

Timecop.freeze(Time.now + restart_worker_interval - mergin_time)
sleep(1)
sleep(1.5)
monitors.count { |m| m.alive? }.should == 0

Timecop.travel(Time.now + 2 * mergin_time)
sleep(1)
sleep(1.5)
monitors.count { |m| m.alive? }.should satisfy { |c| 0 < c && c < workers }

# `start_worker_delay` uses `sleep` inside, so Timecop can't skip this wait.
Expand Down

0 comments on commit bf88f9a

Please sign in to comment.