summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorILYA Khlopotov <iilyak@apache.org>2019-02-15 13:24:28 +0000
committerILYA Khlopotov <iilyak@apache.org>2019-02-15 13:24:28 +0000
commit379015dcb678ce8f47e5dcc7811446abdc7ef7a4 (patch)
treeaae4224454148ec36c7c5f97e6918ef6bffca9dc
parent62e8ba5fe3cc427b19ecc04508dd7dda3c85dbfd (diff)
downloadcouchdb-379015dcb678ce8f47e5dcc7811446abdc7ef7a4.tar.gz
Add tests for config listener restart
-rw-r--r--src/custodian/src/custodian_server.erl50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/custodian/src/custodian_server.erl b/src/custodian/src/custodian_server.erl
index 6ab2f6a77..5198bc33f 100644
--- a/src/custodian/src/custodian_server.erl
+++ b/src/custodian/src/custodian_server.erl
@@ -30,7 +30,11 @@
-define(VSN_0_2_7, 184129240591641721395874905059581858099).
+-ifdef(TEST).
+-define(RELISTEN_DELAY, 50).
+-else.
-define(RELISTEN_DELAY, 5000).
+-endif.
% public functions.
@@ -175,3 +179,49 @@ copies(1) ->
"copy";
copies(_) ->
"copies".
+
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+config_update_test_() ->
+ {
+ "Test config updates",
+ {
+ foreach,
+ fun() -> test_util:start_couch([custodian]) end,
+ fun test_util:stop_couch/1,
+ [
+ fun t_restart_config_listener/1
+ ]
+ }
+}.
+
+t_restart_config_listener(_) ->
+ ?_test(begin
+ ConfigMonitor = config_listener_mon(),
+ ?assert(is_process_alive(ConfigMonitor)),
+ test_util:stop_sync(ConfigMonitor),
+ ?assertNot(is_process_alive(ConfigMonitor)),
+ NewConfigMonitor = test_util:wait(fun() ->
+ case config_listener_mon() of
+ undefined -> wait;
+ Pid -> Pid
+ end
+ end),
+ ?assertNotEqual(ConfigMonitor, NewConfigMonitor),
+ ?assert(is_process_alive(NewConfigMonitor))
+ end).
+
+config_listener_mon() ->
+ IsConfigMonitor = fun(P) ->
+ [M | _] = string:tokens(couch_debug:process_name(P), ":"),
+ M =:= "config_listener_mon"
+ end,
+ [{_, MonitoredBy}] = process_info(whereis(?MODULE), [monitored_by]),
+ case lists:filter(IsConfigMonitor, MonitoredBy) of
+ [Pid] -> Pid;
+ [] -> undefined
+ end.
+
+-endif.