summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2019-07-28 13:05:39 -0400
committerNick Vatamaniuc <vatamane@apache.org>2019-07-28 13:05:39 -0400
commit364d94285cd8dc2d0bc4cef8c0ebb80dc8ecab7a (patch)
tree5be9d44027857ce2f95176efd5467b5781600fad
parenta6c0da1f8959763242153cf11282ee41e6d3f2f9 (diff)
downloadcouchdb-flaky-mem3-sync-eunit-fix.tar.gz
Fix flaky mem3_sync_event_listener EUnit testflaky-mem3-sync-eunit-fix
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.
-rw-r--r--src/mem3/src/mem3_sync_event_listener.erl39
1 files 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 e3368e23f..d7f745137 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.