Skip to content

Commit fc7a893

Browse files
Make policy stop test deterministic. (#70)
1 parent 9e82c58 commit fc7a893

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

test/async/container/policy.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,26 @@ def child_exit(container, child, status, name:, key:, **options)
254254
end.new
255255

256256
container = Async::Container.best_container_class.new(policy: stop_policy)
257+
trigger = IO.pipe
257258

258259
3.times do |i|
259260
container.spawn(name: "worker-#{i}") do |instance|
260261
instance.ready!
261-
exit(1)
262+
263+
# Only the first worker exits, and only once all workers are ready, so exactly one `child_exit` drives the stop. Otherwise multiple simultaneous exits can race the `stopping?` check and inflate `stop_count`.
264+
if i.zero?
265+
trigger.first.gets
266+
exit(1)
267+
else
268+
sleep
269+
end
262270
end
263271
end
264272

273+
container.wait_until_ready
274+
275+
trigger.last.puts("exit")
276+
265277
container.wait
266278

267279
expect(stop_policy.stop_count).to be == 1

0 commit comments

Comments
 (0)