From 980adec58cb6646546cb1fa6d630f1589aab597d Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 21 Feb 2024 01:48:55 +1300 Subject: [PATCH] Add test. --- lib/async/container/generic.rb | 2 ++ test/async/container/forked.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/async/container/generic.rb b/lib/async/container/generic.rb index 6147298..05a4ec9 100644 --- a/lib/async/container/generic.rb +++ b/lib/async/container/generic.rb @@ -49,6 +49,8 @@ def initialize(**options) @keyed = {} end + attr :group + attr :state # A human readable representation of the container. diff --git a/test/async/container/forked.rb b/test/async/container/forked.rb index 42adf4b..39bf4be 100644 --- a/test/async/container/forked.rb +++ b/test/async/container/forked.rb @@ -39,6 +39,40 @@ expect(container.statistics.restarts).to be == 2 end + it "can handle interrupts" do + finished = IO.pipe + interrupted = IO.pipe + + container.spawn(restart: true) do |instance| + Thread.handle_interrupt(Interrupt => :never) do + $stderr.puts "ready" + instance.ready! + + finished.first.gets + $stderr.puts "finishing in child" + rescue ::Interrupt + $stderr.puts "incorrectly interrupted in child" + interrupted.last.puts "incorrectly interrupted" + end + rescue ::Interrupt + $stderr.puts "correctly interrupted in child" + interrupted.last.puts "correctly interrupted" + end + + container.wait_until_ready + + $stderr.puts "interrupting" + container.group.interrupt + + sleep(0.001) + $stderr.puts "finishing" + finished.last.puts "finished" + + expect(interrupted.first.gets).to be == "correctly interrupted\n" + + container.stop + end + it "should be multiprocess" do expect(subject).to be(:multiprocess?) end