summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2020-02-27 14:02:51 -0600
committerPaul J. Davis <paul.joseph.davis@gmail.com>2020-02-28 12:38:59 -0600
commit657420716dd5bcd57becde682ae89e6d80909f86 (patch)
tree5a6a487d223d0254fef6bd5b3c629afee795cae2
parent16304d08581a1e4de8e32d7baf7eddefb0921942 (diff)
downloadcouchdb-657420716dd5bcd57becde682ae89e6d80909f86.tar.gz
Fix mem3_sync_event_listener test
There's a race between the meck:wait call in setup and killing the config_event process. Its possible that we could kill and restart the config_event process after meck:wait returns, but before gen_event:add_sup_handler is called. More likely, we could end up killing the config_event gen_event process before its fully handled the add_sup_handler message and linked the notifier pid. This avoids the race by waiting for config_event to return that it has processed the add_sup_handler message instead of relying on meck:wait for the subscription call.
-rw-r--r--src/mem3/src/mem3_sync_event_listener.erl14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/mem3/src/mem3_sync_event_listener.erl b/src/mem3/src/mem3_sync_event_listener.erl
index b6fbe3279..cad34225d 100644
--- a/src/mem3/src/mem3_sync_event_listener.erl
+++ b/src/mem3/src/mem3_sync_event_listener.erl
@@ -236,7 +236,7 @@ teardown_all(_) ->
setup() ->
{ok, Pid} = ?MODULE:start_link(),
erlang:unlink(Pid),
- meck:wait(config_notifier, subscribe, '_', 1000),
+ wait_config_subscribed(Pid),
Pid.
teardown(Pid) ->
@@ -338,4 +338,16 @@ wait_state(Pid, Field, Val) when is_pid(Pid), is_integer(Field) ->
end,
test_util:wait(WaitFun).
+
+wait_config_subscribed(Pid) ->
+ WaitFun = fun() ->
+ Handlers = gen_event:which_handlers(config_event),
+ Pids = [Id || {config_notifier, Id} <- Handlers],
+ case lists:member(Pid, Pids) of
+ true -> true;
+ false -> wait
+ end
+ end,
+ test_util:wait(WaitFun).
+
-endif.