Skip to content

Commit

Permalink
Ensure disconnection of all user at the end of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geekingfrog committed Apr 27, 2024
1 parent cb89206 commit a96004a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/teiserver/libs/test_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ defmodule Teiserver.TeiserverTestLib do
client.tcp_pid
end

# Ensure that the user is cleanly disconnected. Otherwise it t doesn't fails tests,
# but you get a ton of errors in the console about connection
# pool errors like `Client XXX is still using a connection from owner at location…`
# This is because upon disconnecting, the server does a bunch of DB call for logging
# and telemetry. The disconnection happen when the tcp socket is closed, and by
# that time, the test has ended and the SQL sandbox closed.
ExUnit.Callbacks.on_exit(fn -> Teiserver.Client.disconnect(user.id) end)
%{socket: socket, user: user, pid: pid}
end

Expand Down Expand Up @@ -652,7 +659,7 @@ defmodule Teiserver.TeiserverTestLib do
:telemetry_simple_client_event_types_cache,
:telemetry_simple_lobby_event_types_cache,
:telemetry_simple_match_event_types_cache,
:telemetry_simple_server_event_types_cache,
:telemetry_simple_server_event_types_cache
]

Enum.each(cache_list, fn cache ->
Expand Down
2 changes: 1 addition & 1 deletion test/teiserver/protocols/spring/spring_auth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ defmodule Teiserver.SpringAuthTest do

setup do
%{socket: socket, user: user} = auth_setup()
on_exit(fn -> Client.disconnect(user.id) end)
{:ok, socket: socket, user: user}
end

Expand Down Expand Up @@ -582,6 +581,7 @@ CLIENTS test_room #{user.name}\n"

assert reply ==
"SERVERMSG No incomming match for CREATEBOTACCOUNT with data '\"nomatchname\"'. Userid #{user.id}\n"

end

# test "c.moderation.report", %{socket: socket, user: user} do
Expand Down

0 comments on commit a96004a

Please sign in to comment.