From 358d86508a4f38891a80a43f3c5547d3bdc9450d Mon Sep 17 00:00:00 2001 From: Fernando Mendes Date: Fri, 2 Oct 2020 10:32:50 +0100 Subject: [PATCH] Fix test synchrononization Why: * `on_exit` callbacks run in a separate process, which means that between tests the server might actually still be running. * This is leading to stochastic builds on CI. This change addresses the need by: * Monitoring the server and waiting for it to terminate before exiting the callback --- test/support/http_case.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/support/http_case.ex b/test/support/http_case.ex index fe6b915..08035aa 100644 --- a/test/support/http_case.ex +++ b/test/support/http_case.ex @@ -23,10 +23,18 @@ defmodule HTTPStream.HTTPCase do respond_with: response_module ) - {:ok, _pid} = HTTPServer.start() + {:ok, pid} = HTTPServer.start() on_exit(fn -> + ref = Process.monitor(pid) + HTTPServer.stop() + + receive do + {:DOWN, ^ref, _, _, _} -> + :ok + end + Application.put_env(:http_stream, HTTPServer, config) end)