-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from BKStephens/fix_unstable_async
Fix unstable behavior without `async: false`
- Loading branch information
Showing
24 changed files
with
154 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule ExVCR.MockLock do | ||
use ExActor.GenServer, export: :mock_lock | ||
@ten_milliseconds 10 | ||
|
||
defstart start() do | ||
initial_state(%{lock_holder: nil}) | ||
end | ||
|
||
def ensure_started do | ||
unless Process.whereis(:mock_lock) do | ||
__MODULE__.start | ||
end | ||
end | ||
|
||
defcast request_lock(caller_pid, test_pid) do | ||
Process.send(self(), {:do_request_lock, caller_pid, test_pid}, []) | ||
noreply() | ||
end | ||
|
||
defhandleinfo {:do_request_lock, caller_pid, test_pid}, state: state do | ||
if Map.get(state, :lock_holder) do | ||
Process.send_after(self(), {:do_request_lock, caller_pid, test_pid}, @ten_milliseconds) | ||
noreply() | ||
else | ||
Process.monitor(test_pid) | ||
Process.send(caller_pid, :lock_granted, []) | ||
|
||
state | ||
|> Map.put(:lock_holder, caller_pid) | ||
|> new_state | ||
end | ||
end | ||
|
||
defhandleinfo {:DOWN, _ref, :process, pid, _}, state: state do | ||
if state.lock_holder == pid do | ||
state | ||
|> Map.put(:lock_holder, nil) | ||
|> new_state | ||
else | ||
noreply() | ||
end | ||
end | ||
|
||
defcall release_lock(), state: state do | ||
state | ||
|> Map.put(:lock_holder, nil) | ||
|> set_and_reply(:ok) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.