Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 20, 2024
1 parent 8e2a492 commit 980adec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/async/container/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def initialize(**options)
@keyed = {}
end

attr :group

attr :state

# A human readable representation of the container.
Expand Down
34 changes: 34 additions & 0 deletions test/async/container/forked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 980adec

Please sign in to comment.