You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2019/07/29 18:50:47 UTC

[couchdb] 01/02: Guard against race in config listener test

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

kocolosk pushed a commit to branch jenkins-fix-eunit-timeouts
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit fc56dc019ebb854f3e43403448bf57f977077ab7
Author: Adam Kocoloski <ko...@apache.org>
AuthorDate: Sun Jul 28 11:21:19 2019 -0400

    Guard against race in config listener test
    
    These tests check whether the config subscription is working, but they
    are prone to race conditions because subscribers only learn about config
    changes asynchrnously. We put a 500ms sleep in place to give time for
    the config update to propagate.
    
    As an aside, we also modify the wait function so it only sends one
    get_state message to the server and waits for the reply rather than
    sending a repeated request every time it wakes up.
---
 src/mem3/src/mem3_sync_event_listener.erl | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/mem3/src/mem3_sync_event_listener.erl b/src/mem3/src/mem3_sync_event_listener.erl
index e3368e2..eceda11 100644
--- a/src/mem3/src/mem3_sync_event_listener.erl
+++ b/src/mem3/src/mem3_sync_event_listener.erl
@@ -30,6 +30,7 @@
 
 -ifdef(TEST).
 -define(RELISTEN_DELAY, 500).
+-define(SLEEP, 500).
 -else.
 -define(RELISTEN_DELAY, 5000).
 -endif.
@@ -242,7 +243,7 @@ teardown(Pid) ->
 
 subscribe_for_config_test_() ->
     {
-        "Subscrive for configuration changes",
+        "Subscribe for configuration changes",
         {
             foreach,
             fun setup/0, fun teardown/1,
@@ -294,9 +295,13 @@ should_terminate(Pid) ->
     end).
 
 capture(Pid) ->
+    % The event listener only learns about config changes asynchronously,
+    % so without completely redesigning this test here's a little nap
+    ok = timer:sleep(?SLEEP),
+
     Ref = make_ref(),
+    Pid ! {get_state, Ref, self()},
     WaitFun = fun() ->
-        Pid ! {get_state, Ref, self()},
         receive
             {Ref, State} -> State
         after 0 ->