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/29 00:24:17 UTC

[couchdb] branch fix-mem3-sync-test created (now dbed658)

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

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


      at dbed658  Fix mem3_sync_event_listener EUnit test

This branch includes the following new commits:

     new dbed658  Fix 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 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 fix-mem3-sync-test
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit dbed658a8c0a31ec395f333898ecda304a0538bd
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Sun Jul 28 20:08:46 2019 -0400

    Fix mem3_sync_event_listener EUnit test
    
    Fix a race condition in state matching, also parameterize the state
    field in wait_state.
---
 src/mem3/src/mem3_sync_event_listener.erl | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/src/mem3/src/mem3_sync_event_listener.erl b/src/mem3/src/mem3_sync_event_listener.erl
index d7f7451..cd01a75 100644
--- a/src/mem3/src/mem3_sync_event_listener.erl
+++ b/src/mem3/src/mem3_sync_event_listener.erl
@@ -258,7 +258,7 @@ subscribe_for_config_test_() ->
 should_set_sync_delay(Pid) ->
     ?_test(begin
         config:set("mem3", "sync_delay", "123", false),
-        wait_state_delay(Pid, 123),
+        wait_state(Pid, #state.delay, 123),
         ?assertMatch(#state{delay = 123}, get_state(Pid)),
         ok
     end).
@@ -266,7 +266,7 @@ should_set_sync_delay(Pid) ->
 should_set_sync_frequency(Pid) ->
     ?_test(begin
         config:set("mem3", "sync_frequency", "456", false),
-        wait_state_frequency(Pid, 456),
+        wait_state(Pid, #state.frequency, 456),
         ?assertMatch(#state{frequency = 456}, get_state(Pid)),
         ok
     end).
@@ -306,25 +306,13 @@ get_state(Pid) ->
     end.
 
 
-wait_state_frequency(Pid, Val) ->
-    WaitFun = fun() ->
+wait_state(Pid, Field, Val) when is_pid(Pid), is_integer(Field) ->
+     WaitFun = fun() ->
         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
+            #state{} = S when element(Field, S) == Val ->
+                true;
+            _ ->
+                wait
         end
     end,
     test_util:wait(WaitFun).