Skip to content

Commit

Permalink
Update loadtests code (#861)
Browse files Browse the repository at this point in the history
* Update README file

* Add valtimer and kenzu in loadtests

* Fix override JWT if statement

* Add bushes to new_game function

* Add override_jwt explanation to readme file
  • Loading branch information
Nico-Sanchez authored Aug 23, 2024
1 parent 6ce05ad commit fa09285
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions apps/arena/lib/arena/game_socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule Arena.GameSocketHandler do
_ ->
:cowboy_req.binding(:client_id, req)
end
|> maybe_override_jwt(System.get_env("OVERRIDE_JWT"), req)

game_id = :cowboy_req.binding(:game_id, req)
game_pid = game_id |> Base58.decode() |> :erlang.binary_to_term([:safe])
Expand Down Expand Up @@ -269,4 +270,8 @@ defmodule Arena.GameSocketHandler do
defp handle_decoded_message(message, _) do
Logger.info("Unexpected message: #{inspect(message)}")
end

# This is to override jwt validation for human clients in loadtests.
defp maybe_override_jwt(_client_id, "true", req), do: :cowboy_req.binding(:client_id, req)
defp maybe_override_jwt(client_id, _override_jwt?, _req), do: client_id
end
1 change: 1 addition & 0 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ defmodule Arena.GameUpdater do
|> Map.put(:items, %{})
|> Map.put(:player_timestamps, %{})
|> Map.put(:obstacles, %{})
|> Map.put(:bushes, %{})
|> Map.put(:server_timestamp, 0)
|> Map.put(:client_to_player_map, %{})
|> Map.put(:pools, %{})
Expand Down
10 changes: 7 additions & 3 deletions apps/arena_load_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ Application to load test the Arena backend implementation. It simulates *N* clie
## How to do run our load tests?

```bash
# arena_server_ip is the IP of the server that's running the Arena application
# SERVER_HOST is localhost:4000 if not explicited
export SERVER_HOST=${arena_server_ip}:4000
# We will disable user auth until we find a proper fix for it.
export OVERRIDE_JWT=true
# arena_target_host is the region of the server that's running the Arena application.
# Brazil for example.
# TARGET_SERVER is localhost:4000 if not explicited
export TARGET_SERVER=${arena_target_host}
make run
```

Inside the Elixir shell:
```elixir
# number_of_simulated_players must be a positive integer
number_of_simulated_players = 5000
ArenaLoadTest.SocketSupervisor.spawn_players(number_of_simulated_players)
```

Expand Down
2 changes: 1 addition & 1 deletion apps/arena_load_test/lib/arena_load_test/socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule ArenaLoadTest.SocketHandler do
# This is enough for now. Will request bots from the bots app in future iterations.
# https://github.com/lambdaclass/mirra_backend/issues/410
defp get_random_active_character() do
["muflus", "h4ck", "uma"]
["muflus", "h4ck", "uma", "valtimer", "kenzu"]
|> Enum.random()
end

Expand Down

0 comments on commit fa09285

Please sign in to comment.