Skip to content

Commit

Permalink
Improved error handling if trying to release an unrelated resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 3, 2024
1 parent fdd590d commit e1195f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/async/pool/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def reuse(resource)
Console.debug(self) {"Reuse #{resource}"}
usage = @resources[resource]

if usage.zero?
if usage.nil? || usage.zero?
raise "Trying to reuse unacquired resource: #{resource}!"
end

Expand Down
8 changes: 8 additions & 0 deletions test/async/pool/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
expect(pool).to be(:empty?)
end

it 'raises an error when releasing an unacquired resource' do
resource = Async::Pool::Resource.new

expect do
pool.release(resource)
end.to raise_exception(RuntimeError, message: be =~ /unacquired resource/)
end

with '#as_json' do
it 'generates a JSON representation' do
expect(pool.as_json).to be == {
Expand Down

0 comments on commit e1195f4

Please sign in to comment.