Skip to content

Commit b6d5363

Browse files
Improve controller signal coverage.
Assisted-By: devx/3236e566-7538-432e-a30a-2bdf37265ed4
1 parent f7a4123 commit b6d5363

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

test/async/container/controller.rb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ def controller.setup(container)
230230
expect(signals.handlers).to be == controller.instance_variable_get(:@signals)
231231
end
232232

233+
it "can ignore trapped signals" do
234+
controller.trap(:USR2)
235+
236+
handlers = controller.instance_variable_get(:@signals).to_h
237+
238+
expect(handlers.fetch("USR2")).to be_nil
239+
end
240+
233241
it "queues trapped signal events" do
234242
controller = Async::Container::Controller.new(notify: nil)
235243
applied = false
@@ -251,6 +259,65 @@ def controller.setup(container)
251259
expect(applied).to be == true
252260
end
253261

262+
it "handles setup errors when restarting from a signal" do
263+
def controller.restart
264+
raise Async::Container::SetupError, nil
265+
end
266+
267+
Async::Signals.install(controller.instance_variable_get(:@signals)) do
268+
Process.kill(:HUP, Process.pid)
269+
270+
event = controller.instance_variable_get(:@events).pop(timeout: 1)
271+
272+
expect{event.call}.not.to raise_exception
273+
end
274+
end
275+
276+
it "handles setup errors when reloading from a signal" do
277+
def controller.reload
278+
raise Async::Container::SetupError, nil
279+
end
280+
281+
Async::Signals.install(controller.instance_variable_get(:@signals)) do
282+
Process.kill(:USR1, Process.pid)
283+
284+
event = controller.instance_variable_get(:@events).pop(timeout: 1)
285+
286+
expect{event.call}.not.to raise_exception
287+
end
288+
end
289+
290+
it "notifies when reload fails" do
291+
notify = Object.new
292+
293+
def notify.reloading!
294+
end
295+
296+
def notify.error!(message)
297+
@message = message
298+
end
299+
300+
def notify.message
301+
@message
302+
end
303+
304+
container = Object.new
305+
306+
def container.wait_until_ready
307+
end
308+
309+
def container.failed?
310+
true
311+
end
312+
313+
controller = Async::Container::Controller.new(notify: notify)
314+
315+
controller.instance_variable_set(:@container, container)
316+
317+
expect{controller.reload}.to raise_exception(Async::Container::SetupError)
318+
expect(notify.message).to be == "Container failed to reload!"
319+
end
320+
254321
it "restarts children when receiving SIGHUP" do
255322
expect(input.read(1)).to be == "."
256323

0 commit comments

Comments
 (0)