Skip to content

Commit 980adec

Browse files
committed
Add test.
1 parent 8e2a492 commit 980adec

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/async/container/generic.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def initialize(**options)
4949
@keyed = {}
5050
end
5151

52+
attr :group
53+
5254
attr :state
5355

5456
# A human readable representation of the container.

test/async/container/forked.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,40 @@
3939
expect(container.statistics.restarts).to be == 2
4040
end
4141

42+
it "can handle interrupts" do
43+
finished = IO.pipe
44+
interrupted = IO.pipe
45+
46+
container.spawn(restart: true) do |instance|
47+
Thread.handle_interrupt(Interrupt => :never) do
48+
$stderr.puts "ready"
49+
instance.ready!
50+
51+
finished.first.gets
52+
$stderr.puts "finishing in child"
53+
rescue ::Interrupt
54+
$stderr.puts "incorrectly interrupted in child"
55+
interrupted.last.puts "incorrectly interrupted"
56+
end
57+
rescue ::Interrupt
58+
$stderr.puts "correctly interrupted in child"
59+
interrupted.last.puts "correctly interrupted"
60+
end
61+
62+
container.wait_until_ready
63+
64+
$stderr.puts "interrupting"
65+
container.group.interrupt
66+
67+
sleep(0.001)
68+
$stderr.puts "finishing"
69+
finished.last.puts "finished"
70+
71+
expect(interrupted.first.gets).to be == "correctly interrupted\n"
72+
73+
container.stop
74+
end
75+
4276
it "should be multiprocess" do
4377
expect(subject).to be(:multiprocess?)
4478
end

0 commit comments

Comments
 (0)