Fix tests

This commit is contained in:
Chris McCord 2021-12-16 12:19:02 -05:00
parent dcaf024042
commit b8bbba8ecb
7 changed files with 54 additions and 38 deletions

View file

@ -17,14 +17,19 @@ defmodule LiveBeats.Application do
LiveBeatsWeb.Telemetry,
# Start the PubSub system
{Phoenix.PubSub, name: LiveBeats.PubSub},
#start presence
# start presence
LiveBeatsWeb.Presence,
{Phoenix.Presence.Client,
client: LiveBeats.PresenceClient,
pubsub: LiveBeats.PubSub,
presence: LiveBeatsWeb.Presence,
name: PresenceClient},
# Start the Endpoint (http/https)
LiveBeatsWeb.Endpoint,
LiveBeatsWeb.Endpoint
# Start a worker by calling: LiveBeats.Worker.start_link(arg)
# {LiveBeats.Worker, arg}
] ++ start_presence_client(Mix.env)
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
@ -39,10 +44,4 @@ defmodule LiveBeats.Application do
LiveBeatsWeb.Endpoint.config_change(changed, removed)
:ok
end
defp start_presence_client(:test), do: []
defp start_presence_client(_) do
[{Phoenix.Presence.Client, client: LiveBeats.PresenceClient, pubsub: LiveBeats.PubSub, presence: LiveBeatsWeb.Presence, name: PresenceClient}]
end
end

View file

@ -33,7 +33,7 @@ defmodule LiveBeats.MixProject do
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.6.0"},
{:phoenix, github: "phoenixframework/phoenix", override: true},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.6"},
{:postgrex, ">= 0.0.0"},

View file

@ -20,12 +20,12 @@
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
"mint": {:hex, :mint, "1.3.0", "396b3301102f7b775e103da5a20494b25753aed818d6d6f0ad222a3a018c3600", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "a9aac960562e43ca69a77e5176576abfa78b8398cec5543dd4fb4ab0131d5c1e"},
"phoenix": {:hex, :phoenix, "1.6.2", "6cbd5c8ed7a797f25a919a37fafbc2fb1634c9cdb12a4448d7a5d0b26926f005", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7bbee475acae0c3abc229b7f189e210ea788e63bd168e585f60c299a4b2f9133"},
"phoenix": {:git, "https://github.com/phoenixframework/phoenix.git", "8d2b33ac9691bd624ede602088d213f89600d233", []},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"},
"phoenix_html": {:hex, :phoenix_html, "3.1.0", "0b499df05aad27160d697a9362f0e89fa0e24d3c7a9065c2bd9d38b4d1416c09", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "0c0a98a2cefa63433657983a2a594c7dee5927e4391e0f1bfd3a151d1def33fc"},
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.5.0", "3282d8646e1bfc1ef1218f508d9fcefd48cf47f9081b7667bd9b281b688a49cf", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.6", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.16.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "609740be43de94ae0abd2c4300ff0356a6e8a9487bf340e69967643a59fa7ec8"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"},
"phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "5409845a27938924c0d9a6267b498438a9103295", []},
"phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "d250ad2efd9159c0866def5f5d666bdeeb22ac90", []},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
"phoenix_view": {:hex, :phoenix_view, "1.0.0", "fea71ecaaed71178b26dd65c401607de5ec22e2e9ef141389c721b3f3d4d8011", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "82be3e2516f5633220246e2e58181282c71640dab7afc04f70ad94253025db0c"},
"plug": {:hex, :plug, "1.12.1", "645678c800601d8d9f27ad1aebba1fdb9ce5b2623ddb961a074da0b96c35187d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d57e799a777bc20494b784966dc5fbda91eb4a09f571f76545b72a634ce0d30b"},

View file

@ -1,3 +1,8 @@
defmodule Phoenix.Presence.ClientTest.Presence do
use Phoenix.Presence, otp_app: :live_beats,
pubsub_server: LiveBeats.PubSub
end
defmodule Phoenix.Presence.ClientTest do
use ExUnit.Case
@ -6,11 +11,12 @@ defmodule Phoenix.Presence.ClientTest do
@pubsub LiveBeats.PubSub
@client Phoenix.Presence.Client.Mock
@presence LiveBeatsWeb.Presence
@presence Phoenix.Presence.ClientTest.Presence
@presence_client_opts [client: @client, pubsub: @pubsub, presence: @presence]
setup tags do
start_supervised!({@presence, []})
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(LiveBeats.Repo, shared: not tags[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
@ -21,8 +27,8 @@ defmodule Phoenix.Presence.ClientTest do
presence_key = 1
topic = topic(100)
{:ok, presence_client} = Client.start_link(@presence_client_opts)
{:ok, presence_process} = PresenceMock.start_link(id: presence_key)
{:ok, presence_client} = start_supervised({Client, @presence_client_opts})
{:ok, presence_process} = start_supervised({PresenceMock, id: presence_key})
Phoenix.PubSub.subscribe(@pubsub, topic)
Process.monitor(presence_process)
@ -38,8 +44,8 @@ defmodule Phoenix.Presence.ClientTest do
presence_key = 1
topic = topic(100)
{:ok, presence_client} = Client.start_link(@presence_client_opts)
{:ok, presence_process} = PresenceMock.start_link(id: presence_key)
{:ok, presence_client} = start_supervised({Client, @presence_client_opts})
{:ok, presence_process} = start_supervised({PresenceMock, id: presence_key})
Phoenix.PubSub.subscribe(@pubsub, topic)
Process.monitor(presence_process)
@ -62,9 +68,9 @@ defmodule Phoenix.Presence.ClientTest do
presence_key = 1
topic = topic(100)
{:ok, presence_client} = Client.start_link(@presence_client_opts)
{:ok, presence_process_1} = PresenceMock.start_link(id: presence_key)
{:ok, presence_process_2} = PresenceMock.start_link(id: presence_key)
{:ok, presence_client} = start_supervised({Client, @presence_client_opts})
{:ok, presence_process_1} = start_supervised({PresenceMock, id: presence_key}, id: :mock_1)
{:ok, presence_process_2} = start_supervised({PresenceMock, id: presence_key}, id: :mock_2)
Phoenix.PubSub.subscribe(@pubsub, topic)
@ -74,7 +80,6 @@ defmodule Phoenix.Presence.ClientTest do
PresenceMock.track(presence_client, presence_process_2, topic, presence_key, %{m2: :m2})
assert_receive %{event: "presence_diff"}
client_state = :sys.get_state(presence_client)
assert %{topics: %{^topic => %{"1" => [%{m1: :m1}, %{m2: :m2}]}}} = client_state
@ -84,9 +89,9 @@ defmodule Phoenix.Presence.ClientTest do
presence_key = 1
topic = topic(100)
{:ok, presence_client} = Client.start_link(@presence_client_opts)
{:ok, presence_process_1} = PresenceMock.start_link(id: presence_key)
{:ok, presence_process_2} = PresenceMock.start_link(id: presence_key)
{:ok, presence_client} = start_supervised({Client, @presence_client_opts})
{:ok, presence_process_1} = start_supervised({PresenceMock, id: presence_key}, id: :mock_1)
{:ok, presence_process_2} = start_supervised({PresenceMock, id: presence_key}, id: :mock_2)
Phoenix.PubSub.subscribe(@pubsub, topic)
Process.monitor(presence_process_1)
@ -97,7 +102,6 @@ defmodule Phoenix.Presence.ClientTest do
PresenceMock.track(presence_client, presence_process_2, topic, presence_key, %{m2: :m2})
assert_receive %{event: "presence_diff"}
client_state = :sys.get_state(presence_client)
assert %{topics: %{^topic => %{"1" => [%{m1: :m1}, %{m2: :m2}]}}} = client_state
@ -106,7 +110,7 @@ defmodule Phoenix.Presence.ClientTest do
assert_receive %{event: "presence_diff"}
client_state = :sys.get_state(presence_client)
assert %{topics: %{^topic => %{"1" => [%{m2: :m2}]}}} = client_state
assert %{topics: %{^topic => %{"1" => [%{m2: :m2}]}}} = client_state
end
defp topic(id) do

View file

@ -23,8 +23,8 @@ defmodule LiveBeatsWeb.ProfileLiveTest do
# uploads
assert lv
|> element("#upload-btn")
|> render_click()
|> element("#upload-btn")
|> render_click()
assert render(lv) =~ "Add Songs"
@ -43,16 +43,16 @@ defmodule LiveBeatsWeb.ProfileLiveTest do
[%{"ref" => ref}] = mp3.entries
refute lv
|> form("#song-form")
|> render_change(%{
"_target" => ["songs", ref, "artist"],
"songs" => %{
ref => %{"artist" => "Anon", "attribution" => "", "title" => "silence1s"}
}
}) =~ "can't be blank"
|> form("#song-form")
|> render_change(%{
"_target" => ["songs", ref, "artist"],
"songs" => %{
ref => %{"artist" => "Anon", "attribution" => "", "title" => "silence1s"}
}
}) =~ "can't be blank"
assert {:ok, new_lv, html} =
lv |> form("#song-form") |> render_submit() |> follow_redirect(conn)
lv |> form("#song-form") |> render_submit() |> follow_redirect(conn)
assert_redirected(lv, "/#{current_user.username}")
assert html =~ "1 song(s) uploaded"

View file

@ -35,9 +35,23 @@ defmodule LiveBeatsWeb.ConnCase do
end
end
defp wait_for_children(children_lookup) when is_function(children_lookup) do
Process.sleep(100)
for pid <- children_lookup.() do
ref = Process.monitor(pid)
assert_receive {:DOWN, ^ref, _, _, _}, 1000
end
end
setup tags do
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(LiveBeats.Repo, shared: not tags[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
on_exit(fn ->
wait_for_children(fn -> LiveBeatsWeb.Presence.fetchers_pids() end)
end)
{:ok, conn: Phoenix.ConnTest.build_conn()}
end

View file

@ -1,5 +1,4 @@
defmodule Phoenix.Presence.Client.PresenceMock do
use GenServer
alias Phoenix.Presence.Client