diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2019-07-28 13:05:39 -0400 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2019-07-28 17:21:41 -0400 |
commit | ec2a9637ec220823a4cab2d4b430231ca49ae082 (patch) | |
tree | 5be9d44027857ce2f95176efd5467b5781600fad | |
parent | a6c0da1f8959763242153cf11282ee41e6d3f2f9 (diff) | |
download | couchdb-ec2a9637ec220823a4cab2d4b430231ca49ae082.tar.gz |
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.
-rw-r--r-- | src/mem3/src/mem3_sync_event_listener.erl | 39 |
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. |