diff --git a/test/async/container/.bad.rb b/test/async/container/.bad.rb new file mode 100755 index 0000000..8c3b4c2 --- /dev/null +++ b/test/async/container/.bad.rb @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2020-2022, by Samuel Williams. + +require_relative '../../../lib/async/container/controller' + +class Bad < Async::Container::Controller + def setup(container) + container.run(name: "bad", count: 1, restart: true) do |instance| + # Deliberately missing call to `instance.ready!`: + # instance.ready! + + $stdout.puts "Ready..." + $stdout.flush + + sleep + ensure + $stdout.puts "Exiting..." + $stdout.flush + end + end +end + +controller = Bad.new + +controller.run diff --git a/test/async/container/controller.rb b/test/async/container/controller.rb index 782cab6..5941fd9 100644 --- a/test/async/container/controller.rb +++ b/test/async/container/controller.rb @@ -88,6 +88,38 @@ def controller.setup(container) end end + with 'bad controller' do + let(:controller_path) {File.expand_path(".bad.rb", __dir__)} + + let(:pipe) {IO.pipe} + let(:input) {pipe.first} + let(:output) {pipe.last} + + let(:pid) {@pid} + + def before + @pid = Process.spawn("bundle", "exec", controller_path, out: output) + output.close + + super + end + + def after + Process.kill(:TERM, @pid) + Process.wait(@pid) + + super + end + + it "fails to start" do + expect(input.gets).to be == "Ready...\n" + + Process.kill(:INT, @pid) + + expect(input.gets).to be == "Exiting...\n" + end + end + with 'signals' do let(:controller_path) {File.expand_path(".dots.rb", __dir__)}