You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/07/28 17:09:04 UTC

[couchdb] branch flaky-mem3-sync-eunit-fix created (now 364d942)

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

vatamane pushed a change to branch flaky-mem3-sync-eunit-fix
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 364d942  Fix flaky mem3_sync_event_listener EUnit test

This branch includes the following new commits:

     new 364d942  Fix flaky mem3_sync_event_listener EUnit test

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Fix flaky mem3_sync_event_listener EUnit test

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch flaky-mem3-sync-eunit-fix
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 364d94285cd8dc2d0bc4cef8c0ebb80dc8ecab7a
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Sun Jul 28 13:05:39 2019 -0400

    Fix flaky mem3_sync_event_listener EUnit test
    
    Config setting was asynchronous and the waiting function was not
    waiting for the actual state value to change just that the state
    function was returning.
    
    The fix is to wait for the config value to propagate to the state.
---
 src/mem3/src/mem3_sync_event_listener.erl | 39 ++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/mem3/src/mem3_sync_event_listener.erl b/src/mem3/src/mem3_sync_event_listener.erl
index e3368e2..d7f7451 100644
--- a/src/mem3/src/mem3_sync_event_listener.erl
+++ b/src/mem3/src/mem3_sync_event_listener.erl
@@ -258,14 +258,16 @@ subscribe_for_config_test_() ->
 should_set_sync_delay(Pid) ->
     ?_test(begin
         config:set("mem3", "sync_delay", "123", false),
-        ?assertMatch(#state{delay = 123}, capture(Pid)),
+        wait_state_delay(Pid, 123),
+        ?assertMatch(#state{delay = 123}, get_state(Pid)),
         ok
     end).
 
 should_set_sync_frequency(Pid) ->
     ?_test(begin
         config:set("mem3", "sync_frequency", "456", false),
-        ?assertMatch(#state{frequency = 456}, capture(Pid)),
+        wait_state_frequency(Pid, 456),
+        ?assertMatch(#state{frequency = 456}, get_state(Pid)),
         ok
     end).
 
@@ -293,17 +295,38 @@ should_terminate(Pid) ->
         ok
     end).
 
-capture(Pid) ->
+
+get_state(Pid) ->
     Ref = make_ref(),
+    Pid ! {get_state, Ref, self()},
+    receive
+        {Ref, State} -> State
+    after 10 ->
+        timeout
+    end.
+
+
+wait_state_frequency(Pid, Val) ->
     WaitFun = fun() ->
-        Pid ! {get_state, Ref, self()},
-        receive
-            {Ref, State} -> State
-        after 0 ->
-            wait
+        case get_state(Pid) of
+            timeout ->
+                wait;
+            #state{frequency = Val} ->
+                true
         end
     end,
     test_util:wait(WaitFun).
 
 
+wait_state_delay(Pid, Val) ->
+    WaitFun = fun() ->
+        case get_state(Pid) of
+            timeout ->
+                wait;
+            #state{delay = Val} ->
+                true
+        end
+    end,
+    test_util:wait(WaitFun).
+
 -endif.