From c94877a4824b664a9dcac226fc8a1a002b96d32c Mon Sep 17 00:00:00 2001 From: Piotr Murach Date: Mon, 11 Sep 2023 21:46:15 +0100 Subject: [PATCH] Fix message queue shutdown to raise valid error --- CHANGELOG.md | 1 + lib/finite_machine/message_queue.rb | 8 +++++--- spec/unit/message_queue_spec.rb | 11 +++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b251dbf..2bf811d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Fixed * Fix defining object finalizer in Ruby 3.1 to reference a UUID string by Vadim Kononov(@vkononov) +* Fix message queue shutdown to raise valid error ## [v0.14.0] - 2020-09-12 diff --git a/lib/finite_machine/message_queue.rb b/lib/finite_machine/message_queue.rb index f1cccde..17e8d32 100644 --- a/lib/finite_machine/message_queue.rb +++ b/lib/finite_machine/message_queue.rb @@ -119,16 +119,18 @@ def join(timeout = nil) timeout.nil? ? @thread.join : @thread.join(timeout) end - # Shut down this event queue and clean it up + # Shut down this message queue and clean it up # # @example - # event_queue.shutdown + # message_queue.shutdown + # + # @raise [FiniteMachine::MessageQueueDeadError] # # @return [Boolean] # # @api public def shutdown - raise EventQueueDeadError, "event queue already dead" if @dead + raise MessageQueueDeadError, "message queue already dead" if @dead queue = [] @mutex.synchronize do diff --git a/spec/unit/message_queue_spec.rb b/spec/unit/message_queue_spec.rb index 1febfa5..c355ee9 100644 --- a/spec/unit/message_queue_spec.rb +++ b/spec/unit/message_queue_spec.rb @@ -59,4 +59,15 @@ expect(event_queue.running?).to be(false) event_queue.join(0.001) end + + it "raises an error when the message queue is already shut down" do + message_queue = described_class.new + message_queue.start + message_queue.shutdown + + expect { + message_queue.shutdown + }.to raise_error(FiniteMachine::MessageQueueDeadError, + "message queue already dead") + end end