You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2020/02/28 18:39:09 UTC

[couchdb] branch 3.0.x updated: Fix mem3_sync_event_listener test

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch 3.0.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/3.0.x by this push:
     new 6574207  Fix mem3_sync_event_listener test
6574207 is described below

commit 657420716dd5bcd57becde682ae89e6d80909f86
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Feb 27 14:02:51 2020 -0600

    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.
---
 src/mem3/src/mem3_sync_event_listener.erl | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/mem3/src/mem3_sync_event_listener.erl b/src/mem3/src/mem3_sync_event_listener.erl
index b6fbe32..cad3422 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.