Skip to content
Permalink
Browse files
Increase meck_proc stop timeout to infinity
When stopping (e.g. due to meck:unload/1), meck_procs restore
the original module, which may be a time consuming operation.
If a gen_server:call is used for stopping, there's risk of a
timeout that will be translated to a confusing
error:{not_mocked, ...}.

Using gen_server:stop/1 breaks tests, so using an infinity timeout
instead.
  • Loading branch information
aronisstav authored and eproxus committed May 26, 2021
1 parent 3efce27 commit 74a2ac7720857563b1ebcad3a5c5c976197f5475
Showing 2 changed files with 13 additions and 1 deletion.
@@ -11,6 +11,10 @@ The format is based on [Keep a Changelog], and this project adheres to

- Leave module loaded state as it was [\#228](https://github.com/eproxus/meck/pull/228)

### Fixed

- Fix misleading not_mocked errors when when unloading a mock [\#231](https://github.com/eproxus/meck/pull/231)

## [0.9.2] - 2021-03-06

### Fixed
@@ -188,7 +188,9 @@ invalidate(Mod) ->

-spec stop(Mod::atom()) -> ok.
stop(Mod) ->
gen_server(call, Mod, stop).
%% To avoid timeout due to slow original restoration. gen_server:stop/1
%% would be better, but some tests are then tricky to fix.
gen_server(call, Mod, stop, infinity).

%%%============================================================================
%%% gen_server callbacks
@@ -496,6 +498,12 @@ init_expects(Exports, Options) ->
end,
dict:new(), Expects).

-spec gen_server(Method:: call, Mod::atom(), Msg :: stop, timeout()) -> any().
gen_server(call, Mod, stop, infinity) ->
Name = meck_util:proc_name(Mod),
try gen_server:call(Name, stop, infinity)
catch exit:_Reason -> erlang:error({not_mocked, Mod}) end.

-spec gen_server(Method:: call | cast, Mod::atom(), Msg::tuple() | atom()) -> any().
gen_server(Func, Mod, Msg) ->
Name = meck_util:proc_name(Mod),

0 comments on commit 74a2ac7

Please sign in to comment.