Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent "mix test" results based on order of execution #366

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions test/teiserver/battle/lobby_server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Teiserver.Battle.LobbyServerTest do
founder_id: host.id,
founder_name: host.name,
cmd: "c.lobby.create",
name: "ServerName",
name: "LobbyServerTest",
nattype: "none",
port: 1234,
game_hash: "string_of_characters",
Expand Down Expand Up @@ -69,8 +69,8 @@ defmodule Teiserver.Battle.LobbyServerTest do
founder_id: host.id,
founder_name: host.name,
cmd: "c.lobby.create",
name: "ServerName",
base_name: "ServerName",
name: "LobbyServerTestRename",
base_name: "LobbyServerTestRename",
nattype: "none",
type: "normal",
port: 1234,
Expand All @@ -92,6 +92,7 @@ defmodule Teiserver.Battle.LobbyServerTest do
p = LobbyLib.start_lobby_server(lobby)
Coordinator.start_consul(lobby_id)
assert is_pid(p)
assert LobbyLib.lobby_exists?(lobby_id) == true

LobbyLib.rename_lobby(lobby_id, "base name", host.id)
c = LobbyLib.call_lobby(lobby_id, :get_lobby_state)
Expand Down Expand Up @@ -119,5 +120,8 @@ defmodule Teiserver.Battle.LobbyServerTest do
c = LobbyLib.call_lobby(lobby_id, :get_lobby_state)
assert c.id == lobby_id
assert c.name == "other name | Rating: 10-50"

LobbyLib.stop_lobby_server(lobby_id)
assert LobbyLib.lobby_exists?(lobby_id) == false
end
end
5 changes: 5 additions & 0 deletions test/teiserver/data/battle/lobby_chat_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ defmodule Teiserver.Data.Battle.ChatLibTest do
})
|> Lobby.add_lobby()

assert Lobby.get_lobby(lobby.id) != nil

Battle.set_modoption(lobby.id, "server/match/uuid", UUID.uuid1())

{:ok, chat_log} = ChatLib.persist_message(bot_user, "Message from the bot", lobby.id, :say)
Expand All @@ -34,5 +36,8 @@ defmodule Teiserver.Data.Battle.ChatLibTest do

assert chat_log.user_id == real_user.id
assert chat_log.content == "g: Message from the user"

Lobby.close_lobby(lobby.id)
assert Lobby.get_lobby(lobby.id) == nil
end
end
7 changes: 6 additions & 1 deletion test/teiserver/lobby/commands/explain_command_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Teiserver.Lobby.Commands.ExplainCommandTest do
@moduledoc false
use Teiserver.ServerCase, async: false
alias Teiserver.{Battle, Coordinator, TeiserverTestLib}
alias Teiserver.Lobby
alias Teiserver.Lobby.ChatLib
alias Teiserver.Common.PubsubListener

Expand All @@ -13,7 +14,8 @@ defmodule Teiserver.Lobby.Commands.ExplainCommandTest do
Coordinator.start_coordinator()

user = TeiserverTestLib.new_user()
lobby_id = TeiserverTestLib.make_lobby()
lobby_id = TeiserverTestLib.make_lobby(%{name: "ExplainCommandTestText"})
assert Lobby.get_lobby(lobby_id) != nil
chat_listener = PubsubListener.new_listener(["teiserver_lobby_chat:#{lobby_id}"])
client_listener = PubsubListener.new_listener(["teiserver_client_messages:#{user.id}"])

Expand Down Expand Up @@ -50,6 +52,9 @@ defmodule Teiserver.Lobby.Commands.ExplainCommandTest do
}

assert Enum.member?(messages, expected_message)

Lobby.close_lobby(lobby_id)
assert Lobby.get_lobby(lobby_id) == nil
end
end

Expand Down
19 changes: 16 additions & 3 deletions test/teiserver_web/live/account/profile/overview_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule TeiserverWeb.Live.Account.Profile.OverviewTest do

alias Central.Helpers.GeneralTestLib
alias Teiserver.{Battle, TeiserverTestLib, Client}
alias Teiserver.Lobby

setup do
{:ok, data} =
Expand All @@ -25,7 +26,7 @@ defmodule TeiserverWeb.Live.Account.Profile.OverviewTest do
} do
login_user(user)

lobby_id = TeiserverTestLib.make_lobby()
lobby_id = TeiserverTestLib.make_lobby(%{name: "OverviewTestJoin"})

Battle.force_add_user_to_lobby(profile_user.id, lobby_id)

Expand All @@ -36,13 +37,17 @@ defmodule TeiserverWeb.Live.Account.Profile.OverviewTest do
|> render_click()

assert user.id in Battle.get_lobby_member_list(lobby_id)

assert Lobby.get_lobby(lobby_id) != nil
Lobby.close_lobby(lobby_id)
assert Lobby.get_lobby(lobby_id) == nil
end

test "only renders join button when user to join is in a lobby", %{
conn: conn,
profile_user: profile_user
} do
lobby_id = TeiserverTestLib.make_lobby()
lobby_id = TeiserverTestLib.make_lobby(%{name: "OverviewTestJoinRender"})

{:ok, view, _html} = live(conn, "/profile/#{profile_user.id}")

Expand All @@ -55,6 +60,10 @@ defmodule TeiserverWeb.Live.Account.Profile.OverviewTest do
assert view
|> element("span[phx-click=join]")
|> has_element?()

assert Lobby.get_lobby(lobby_id) != nil
Lobby.close_lobby(lobby_id)
assert Lobby.get_lobby(lobby_id) == nil
end

@tag :needs_attention
Expand All @@ -64,7 +73,8 @@ defmodule TeiserverWeb.Live.Account.Profile.OverviewTest do
} do
# Skip client login

lobby_id = TeiserverTestLib.make_lobby()
lobby_id = TeiserverTestLib.make_lobby(%{name: "OverviewTestFlash"})
assert Lobby.get_lobby(lobby_id) != nil

Battle.force_add_user_to_lobby(profile_user.id, lobby_id)

Expand All @@ -75,6 +85,9 @@ defmodule TeiserverWeb.Live.Account.Profile.OverviewTest do
|> render_click()

assert render(view) =~ "Client is not connected"

DeviousNull marked this conversation as resolved.
Show resolved Hide resolved
Lobby.close_lobby(lobby_id)
assert Lobby.get_lobby(lobby_id) == nil
end
end

Expand Down
Loading