Skip to content

Commit

Permalink
Fix message queue shutdown to raise valid error
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Sep 11, 2023
1 parent 51fbf38 commit c94877a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions lib/finite_machine/message_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/message_queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c94877a

Please sign in to comment.