From 60b21af7b93e27acd2ad084f92c279846c2b4e63 Mon Sep 17 00:00:00 2001 From: Sebastien Merle Date: Wed, 27 Nov 2024 12:28:20 +0100 Subject: [PATCH] Try fixing CT error on CI 2 --- test/grisp_connect_api_SUITE.erl | 1 + test/grisp_connect_connection_SUITE.erl | 1 + test/grisp_connect_log_SUITE.erl | 1 + test/grisp_connect_test_server.erl | 23 +++++++++++------------ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/test/grisp_connect_api_SUITE.erl b/test/grisp_connect_api_SUITE.erl index e4db4c4..3c09b25 100644 --- a/test/grisp_connect_api_SUITE.erl +++ b/test/grisp_connect_api_SUITE.erl @@ -52,6 +52,7 @@ init_per_testcase(TestCase, Config) -> end_per_testcase(_, Config) -> ok = application:stop(grisp_connect), + grisp_connect_test_server:wait_disconnection(), ?assertEqual([], flush()), Config. diff --git a/test/grisp_connect_connection_SUITE.erl b/test/grisp_connect_connection_SUITE.erl index 5d7d336..295ca02 100644 --- a/test/grisp_connect_connection_SUITE.erl +++ b/test/grisp_connect_connection_SUITE.erl @@ -88,6 +88,7 @@ init_per_testcase(_TestCase, Config) -> Config. end_per_testcase(_, Config) -> + grisp_connect_test_server:wait_disconnection(), ?assertEqual([], flush()), Config. diff --git a/test/grisp_connect_log_SUITE.erl b/test/grisp_connect_log_SUITE.erl index 56a843c..583736d 100644 --- a/test/grisp_connect_log_SUITE.erl +++ b/test/grisp_connect_log_SUITE.erl @@ -50,6 +50,7 @@ end_per_testcase(log_level_test, Config) -> end_per_testcase(other, Config); end_per_testcase(_, Config) -> ok = application:stop(grisp_connect), + grisp_connect_test_server:wait_disconnection(), ?assertEqual([], flush()), Config. diff --git a/test/grisp_connect_test_server.erl b/test/grisp_connect_test_server.erl index db46f64..97cb832 100644 --- a/test/grisp_connect_test_server.erl +++ b/test/grisp_connect_test_server.erl @@ -21,6 +21,7 @@ -export([send_jsonrpc_request/3]). -export([send_jsonrpc_result/2]). -export([send_jsonrpc_error/3]). +-export([wait_disconnection/0]). % Websocket Callbacks -export([init/2]). @@ -50,7 +51,7 @@ stop(Apps) -> ?assertEqual(ok, stop_cowboy()), [?assertEqual(ok, application:stop(App)) || App <- Apps], % Ensure the process is unregistered... - wait_no_websocket(). + wait_disconnection(). % Start the cowboy listener. @@ -186,6 +187,15 @@ send_jsonrpc_error(Code, Msg, Id) -> id => Id}, send_text(jsx:encode(Map)). +wait_disconnection() -> + case whereis(?MODULE) of + undefined -> ok; + _Pid -> + timer:sleep(200), + wait_disconnection() + end. + + %--- Websocket Callbacks ------------------------------------------------------- init(Req, State) -> @@ -213,14 +223,3 @@ websocket_info(close_websocket, State) -> websocket_info(Info, State) -> ct:pal("Ignore websocket info:~n~p", [Info]), {[], State}. - - -%--- Internal Functions -------------------------------------------------------- - -wait_no_websocket() -> - case whereis(?MODULE) of - undefined -> ok; - _Pid -> - timer:sleep(200), - wait_no_websocket() - end.