Skip to content

Commit

Permalink
Merge pull request #4241 from esl/muc-suite-fix-init-per-group
Browse files Browse the repository at this point in the history
Fix flaky `init_per_group` in the MUC suite

This PR fixes a problem where tests might fail if an HTTP listener has already been started in the init_per_group function of the MUC suite.

Sometimes, if other tests that need an HTTP listener don't work right, they can leave the listener running. This causes a problem when trying to start it again in the init_per_group.
  • Loading branch information
NelsonVides committed Mar 13, 2024
2 parents 23a4f06 + a75eaf1 commit 7ae0848
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 10 additions & 2 deletions big_tests/tests/http_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@
start(Port, Path, HandleFun) ->
application:ensure_all_started(cowboy),
Dispatch = cowboy_router:compile([{'_', [{Path, http_helper, HandleFun}]}]),
{ok, _} = cowboy:start_clear(http_helper_listener, [{port, Port}],
#{env => #{dispatch => Dispatch}}).
case cowboy:start_clear(http_helper_listener, [{port, Port}],
#{env => #{dispatch => Dispatch}}) of
{ok, Pid} ->
{ok, Pid};
{error, {already_started, _}} ->
ct:log("http_helper_listener was already running. Restarting it."),
stop(),
{ok, _} = cowboy:start_clear(http_helper_listener, [{port, Port}],
#{env => #{dispatch => Dispatch}})
end.

stop() ->
cowboy:stop_listener(http_helper_listener).
Expand Down
1 change: 0 additions & 1 deletion big_tests/tests/muc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ end_per_suite(Config) ->
dynamic_modules:restore_modules(Config),
escalus:end_per_suite(Config).


init_per_group(room_registration_race_condition, Config) ->
escalus_fresh:create_users(Config, [{alice, 1}]);

Expand Down

0 comments on commit 7ae0848

Please sign in to comment.