From 0e1edc47cd2f69325df04bc8c85d14f141ba410b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Szuma?= Date: Wed, 22 May 2024 11:01:46 +0200 Subject: [PATCH] Experimental fix of auth cache error --- test/fishjam/component/hls/manager_test.exs | 23 ++++++++++++-- .../integration/peer_socket_test.exs | 30 ++++++++++++++----- .../integration/server_notification_test.exs | 5 ++-- test/support/mock_manager.ex | 6 ++++ 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/test/fishjam/component/hls/manager_test.exs b/test/fishjam/component/hls/manager_test.exs index a390e02b..049e7d6b 100644 --- a/test/fishjam/component/hls/manager_test.exs +++ b/test/fishjam/component/hls/manager_test.exs @@ -32,6 +32,23 @@ defmodule Fishjam.Component.HLS.ManagerTest do setup :verify_on_exit! setup :set_mox_from_context + defmodule Adapter do + @moduledoc false + + @behaviour ExAws.Config.AuthCache.AuthConfigAdapter + + @config %{ + access_key_id: "AKIAIOSFODNN7EXAMPLE", + secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", + region: "us-east-1" + } + + @impl true + def adapt_auth_config(_config, _profile, _expiration) do + @config + end + end + test "Spawn manager without credentials", %{ room_id: room_id, hls_dir: hls_dir, @@ -51,16 +68,18 @@ defmodule Fishjam.Component.HLS.ManagerTest do end test "Spawn manager with credentials", %{room_id: room_id, hls_dir: hls_dir, options: options} do - MockManager.http_mock_expect(4, status_code: 200) + Application.put_env(:ex_aws, :awscli_auth_adapter, Adapter) + + MockManager.http_mock_stub(status_code: 200) pid = MockManager.start_mock_engine() {:ok, manager} = Manager.start(room_id, pid, hls_dir, %{options | s3: @s3_credentials}) ref = Process.monitor(manager) - MockManager.kill_mock_engine(pid) assert_receive {:DOWN, ^ref, :process, ^manager, :normal} assert length(File.ls!(hls_dir)) == 4 + Application.delete_env(:ex_aws, :awscli_auth_adapter) end test "Spawn manager with persistent false", %{ diff --git a/test/fishjam_web/integration/peer_socket_test.exs b/test/fishjam_web/integration/peer_socket_test.exs index 684c1546..f81a04c9 100644 --- a/test/fishjam_web/integration/peer_socket_test.exs +++ b/test/fishjam_web/integration/peer_socket_test.exs @@ -24,9 +24,10 @@ defmodule FishjamWeb.Integration.PeerSocketTest do alias FishjamWeb.PeerSocket - socket "/socket/peer", PeerSocket, + socket("/socket/peer", PeerSocket, websocket: true, longpoll: false + ) end setup_all do @@ -178,13 +179,26 @@ defmodule FishjamWeb.Integration.PeerSocketTest do "fishjam_rooms" => "1" } - Process.sleep(1_000) - - metrics_to_compare = get_peers_room_metrics() - - for {k, v} <- metrics_after_one_tick do - assert Map.fetch!(metrics_to_compare, k) == v - end + assert Enum.reduce_while(0..15, false, fn _num, _acc -> + Process.sleep(100) + metrics_to_compare = get_peers_room_metrics() + + all_metrics_present? = + Enum.all?(metrics_after_one_tick, fn {k, _v} -> + is_map_key(metrics_to_compare, k) + end) + + if all_metrics_present? do + for {k, v} <- metrics_after_one_tick do + assert Map.fetch!(metrics_to_compare, k) == v + end + + {:halt, true} + else + {:cont, false} + end + end), + "Metrics isn't present after 1,5 second" conn = delete(conn, ~p"/room/#{room_id}/") response(conn, :no_content) diff --git a/test/fishjam_web/integration/server_notification_test.exs b/test/fishjam_web/integration/server_notification_test.exs index aa15aae0..5c63a33c 100644 --- a/test/fishjam_web/integration/server_notification_test.exs +++ b/test/fishjam_web/integration/server_notification_test.exs @@ -385,9 +385,10 @@ defmodule FishjamWeb.Integration.ServerNotificationTest do type: :TRACK_TYPE_VIDEO, metadata: "\"myvideo\"" } = track_info - } = track_added + } = track_added, + 1_000 - assert_receive {:webhook_notification, ^track_added}, 1000 + assert_receive {:webhook_notification, ^track_added} GenServer.stop(peer_ws) diff --git a/test/support/mock_manager.ex b/test/support/mock_manager.ex index 5e86f335..29150459 100644 --- a/test/support/mock_manager.ex +++ b/test/support/mock_manager.ex @@ -13,6 +13,12 @@ defmodule MockManager do end) end + def http_mock_stub(status_code: status_code) do + stub(ExAws.Request.HttpMock, :request, fn _method, _url, _req_body, _headers, _http_opts -> + {:ok, %{status_code: status_code, body: %{}}} + end) + end + def start_mock_engine(), do: spawn(fn ->