summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2019-07-28 20:08:46 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2019-07-30 02:25:35 -0400
commite67903b831799568425ce93abe4589c3ee59f558 (patch)
treec2855e07245066cd3cd459e942c1f0d0d3423e9c
parent220462a1dd2d921fc4ecba3488f5fedefb75217f (diff)
downloadcouchdb-e67903b831799568425ce93abe4589c3ee59f558.tar.gz
Fix mem3_sync_event_listener EUnit test
Fix a race condition in state matching, also parameterize the state field in wait_state.
-rw-r--r--src/mem3/src/mem3_sync_event_listener.erl28
1 files 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 d7f745137..69a7a6017 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).
@@ -301,30 +301,18 @@ get_state(Pid) ->
Pid ! {get_state, Ref, self()},
receive
{Ref, State} -> State
- after 10 ->
+ after 500 ->
timeout
end.
-wait_state_frequency(Pid, Val) ->
+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).