From 5230a531805fabed9213cd09b55202560403e92a Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Thu, 14 Dec 2023 23:45:21 +0100 Subject: [PATCH] test: fix flaky test --- test/ehttpc_sup_tests.erl | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/test/ehttpc_sup_tests.erl b/test/ehttpc_sup_tests.erl index 8ed0c0a..ccefec7 100644 --- a/test/ehttpc_sup_tests.erl +++ b/test/ehttpc_sup_tests.erl @@ -44,23 +44,18 @@ t_shutdown() -> Worker ! {suspend, timer:seconds(60)}, %% zombie worker should not block pool stop ok = ehttpc_sup:stop_pool(Pool), - receive - {'DOWN', _, process, SupPid, killed} -> - ok; - Other2 -> - error({"unexpected_message", Other2}) - after 6000 -> - error("failed_to_stop_pool_supervisor") - end, - receive - {'DOWN', _, process, Worker, killed} -> - ok; - Other -> - error({"unexpected_message", Other}) - after 1000 -> - error("failed_to_stop_worker_from_sup_shutdown") - end + ok = wait_for_down([SupPid, Worker]) after exit(SupPid, kill), exit(Worker, kill) end. + +wait_for_down([]) -> + ok; +wait_for_down(Pids) -> + receive + {'DOWN', _, process, Pid, killed} -> + wait_for_down(Pids -- [Pid]) + after 10_000 -> + error(timeout) + end.