Skip to content

Commit

Permalink
Merge pull request #610 from geekingfrog/fix-matchmaking-tests
Browse files Browse the repository at this point in the history
Ensure matchmaking queues are terminated after the tests
  • Loading branch information
geekingfrog authored Feb 26, 2025
2 parents 4307777 + 44f0da2 commit 2d5797f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 10 additions & 0 deletions lib/teiserver/matchmaking/queue_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ defmodule Teiserver.Matchmaking.QueueSupervisor do
end
end

def terminate_queue(id) do
case Teiserver.Matchmaking.QueueRegistry.lookup(id) do
nil ->
:ok

pid ->
Horde.DynamicSupervisor.terminate_child(__MODULE__, pid)
end
end

def start_link(init_arg) do
{:ok, sup} = Horde.DynamicSupervisor.start_link(__MODULE__, init_arg, name: __MODULE__)

Expand Down
22 changes: 17 additions & 5 deletions test/teiserver_web/tachyon/matchmaking_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ defmodule Teiserver.Tachyon.MatchmakingTest do
games: game_versions(),
maps: []
})
|> QueueSupervisor.start_queue!()
|> start_queue()

resp = Tachyon.list_queues!(client)

Expand Down Expand Up @@ -216,7 +216,7 @@ defmodule Teiserver.Tachyon.MatchmakingTest do
games: game_versions(),
maps: map_attrs(id)
})
|> QueueSupervisor.start_queue!()
|> start_queue()

assert %{"status" => "failed", "reason" => "invalid_request"} =
Tachyon.join_queues!(client, [id])
Expand All @@ -235,7 +235,7 @@ defmodule Teiserver.Tachyon.MatchmakingTest do
games: game_versions(),
maps: map_attrs(id)
})
|> QueueSupervisor.start_queue!()
|> start_queue()

assert %{"status" => "failed", "reason" => "internal_error"} =
Tachyon.join_queues!(client, [id])
Expand All @@ -254,7 +254,7 @@ defmodule Teiserver.Tachyon.MatchmakingTest do
games: [],
maps: map_attrs(id)
})
|> QueueSupervisor.start_queue!()
|> start_queue()

assert %{"status" => "failed", "reason" => "internal_error"} =
Tachyon.join_queues!(client, [id])
Expand All @@ -273,7 +273,7 @@ defmodule Teiserver.Tachyon.MatchmakingTest do
games: game_versions(),
maps: []
})
|> QueueSupervisor.start_queue!()
|> start_queue()

assert %{"status" => "failed", "reason" => "internal_error"} =
Tachyon.join_queues!(client, [id])
Expand Down Expand Up @@ -721,4 +721,16 @@ defmodule Teiserver.Tachyon.MatchmakingTest do
}
}} = Tachyon.recv_message(client, timeout: 10)
end

defp start_queue(state) do
QueueSupervisor.start_queue!(state)

ExUnit.Callbacks.on_exit(fn ->
Teiserver.Matchmaking.QueueSupervisor.terminate_queue(state.id)

Teiserver.Support.Polling.poll_until_nil(fn ->
Teiserver.Matchmaking.lookup_queue(state.id)
end)
end)
end
end

0 comments on commit 2d5797f

Please sign in to comment.