This is an automated email from the ASF dual-hosted git repository. vatamane pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/couchdb-meck.git
commit 74a2ac7720857563b1ebcad3a5c5c976197f5475 Author: Stavros Aronis <[email protected]> AuthorDate: Wed May 12 14:19:13 2021 +0200 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. --- CHANGELOG.md | 4 ++++ src/meck_proc.erl | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e5d34..76571c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/meck_proc.erl b/src/meck_proc.erl index b1500c6..459246f 100644 --- a/src/meck_proc.erl +++ b/src/meck_proc.erl @@ -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),
