Skip to content

Commit

Permalink
Experimental fix of auth cache error
Browse files Browse the repository at this point in the history
  • Loading branch information
Rados13 committed May 23, 2024
1 parent 78ca76e commit 0e1edc4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
23 changes: 21 additions & 2 deletions test/fishjam/component/hls/manager_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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", %{
Expand Down
30 changes: 22 additions & 8 deletions test/fishjam_web/integration/peer_socket_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/fishjam_web/integration/server_notification_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions test/support/mock_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down

0 comments on commit 0e1edc4

Please sign in to comment.