Skip to content

Commit

Permalink
Introduce mutex Monitor in Faraday::Test::Stubs (#1379)
Browse files Browse the repository at this point in the history
Fixes #1365
  • Loading branch information
iMacTia authored Jan 12, 2022
1 parent 026e956 commit 996028a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/faraday/adapter/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def initialize(strict_mode: false)
@stack = {}
@consumed = {}
@strict_mode = strict_mode
@stubs_mutex = Monitor.new
yield(self) if block_given?
end

Expand All @@ -72,7 +73,10 @@ def match(env)

stub, meta = matches?(stack, env)
if stub
consumed << stack.delete(stub)
@stubs_mutex.synchronize do
removed = stack.delete(stub)
consumed << removed unless removed.nil?
end
return stub, meta
end
matches?(consumed, env)
Expand Down

0 comments on commit 996028a

Please sign in to comment.