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..f4ed5d4 100644 --- a/test/async/container/forked.rb +++ b/test/async/container/forked.rb @@ -39,6 +39,33 @@ 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 + instance.ready! + + finished.first.gets + rescue ::Interrupt + interrupted.last.puts "incorrectly interrupted" + end + rescue ::Interrupt + interrupted.last.puts "correctly interrupted" + end + + container.wait_until_ready + + container.group.interrupt + sleep(0.001) + 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