diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-02-27 14:02:51 -0600 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-02-27 14:45:21 -0600 |
commit | 7a33ca09e15b3a995afab373dbc9162ec9272d4a (patch) | |
tree | 7fb93be0606d6d6be59052fdfe8b2f57aa424c03 | |
parent | 65bc5b0eab5d4a3e902e63cd768c564c7a704082 (diff) | |
download | couchdb-7a33ca09e15b3a995afab373dbc9162ec9272d4a.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.erl | 14 |
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. |