From 2f90ff1bbbb86befeb5b055093322578a8395290 Mon Sep 17 00:00:00 2001 From: "John R. Daily" Date: Thu, 9 Mar 2017 13:57:56 -0500 Subject: [PATCH] Kill lingering supervisors If an earlier test fails, `teardown` may not be invoked properly and later tests will fail during `setup`. Terminate lingering supervisors. --- src/riak_core_info_service.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/riak_core_info_service.erl b/src/riak_core_info_service.erl index c40282426..fc1eb9149 100644 --- a/src/riak_core_info_service.erl +++ b/src/riak_core_info_service.erl @@ -162,7 +162,16 @@ sup_wrapper() -> %% Launching and terminating the supervisor is an async operation with %% all the non-determinism that that implies. So, we wait. -sup_wait(Name, Fun) -> +sup_wait(Name, kill, Fun) -> + %% in case an earlier test failure left a supervisor running + case whereis(Name) of + undefined -> + ok; + Pid -> + exit(Pid, kill) + end, + sup_wait(Name, undefined, Fun); +sup_wait(Name, undefined, Fun) -> sup_wait(Name, Fun, Fun(whereis(Name)), 5). sup_wait(_Name, _Fun, ok, _Count) -> @@ -194,9 +203,9 @@ setup() -> end, flush_messages(), - sup_wait(riak_core_info_service_sup, WaitTerminated), + sup_wait(riak_core_info_service_sup, kill, WaitTerminated), Pid = spawn(fun sup_wrapper/0), - sup_wait(riak_core_info_service_sup, WaitStarted), + sup_wait(riak_core_info_service_sup, undefined, WaitStarted), Pid.