summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Avdey <eiri@eiri.ca>2017-06-08 19:37:39 -0300
committerEric Avdey <eiri@eiri.ca>2017-06-16 15:54:15 -0300
commit3f37ec15ea8cefb895418b13e481a4bd6d27ae6a (patch)
tree3129cbbf9c1aaa1cdb20417c4a6c4355571685db
parenta00d6834ea0f614cc59276b4421bf306feeb4573 (diff)
downloadcouchdb-3f37ec15ea8cefb895418b13e481a4bd6d27ae6a.tar.gz
Wait for listener's exit during restart test
To test a config listener's restart we are deleting event handler in config_event and then immediately checking event manager. This creates race when we can be a slightly early and catch old handler yet to be removed or slightly late and get new handler that already been installed. This patch addresses this by waiting for the old listener to quit and then waiting for a new handler to be installed.
-rw-r--r--src/couch_log/test/couch_log_config_listener_test.erl23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/couch_log/test/couch_log_config_listener_test.erl b/src/couch_log/test/couch_log_config_listener_test.erl
index e3680b881..07abae1ff 100644
--- a/src/couch_log/test/couch_log_config_listener_test.erl
+++ b/src/couch_log/test/couch_log_config_listener_test.erl
@@ -16,6 +16,7 @@
-include_lib("couch_log/include/couch_log.hrl").
-include_lib("eunit/include/eunit.hrl").
+-define(TIMEOUT, 1000).
couch_log_config_test_() ->
{setup,
@@ -34,13 +35,27 @@ check_restart_listener() ->
Handler1 = get_handler(),
?assertNotEqual(not_found, Handler1),
+ Ref = erlang:monitor(process, Listener1),
ok = gen_event:delete_handler(config_event, get_handler(), testing),
- ?assertEqual(not_found, get_handler()),
- timer:sleep(100),
- ?assertNot(is_process_alive(Listener1)),
+ receive
+ {'DOWN', Ref, process, _, _} ->
+ ?assertNot(is_process_alive(Listener1))
+ after ?TIMEOUT ->
+ erlang:error({timeout, config_listener_mon_death})
+ end,
+
+ NewHandler = test_util:wait(fun() ->
+ case get_handler() of
+ not_found -> wait;
+ Reply -> Reply
+ end
+ end, ?TIMEOUT, 20),
+ ?assertEqual(Handler1, NewHandler),
- ?assert(is_process_alive(get_listener())),
+ Listener2 = get_listener(),
+ ?assert(is_process_alive(Listener2)),
+ ?assertNotEqual(Listener1, Listener2),
ok.
check_ignore_non_log() ->