Conversation
|
Interesting: In step 2, I only see the errors if I can confirm that in step 3, the error disappears. |
|
Interesting. Yeah, if I run If I run |
|
I'll rebase this PR |
|
With these changes to this PRDiff below contains: - your step 3 - with multiple async browser test suites - but without `@tag sandbox_shutdown_delay: 200`diff --git a/mix.exs b/mix.exs
index d5ce0f1..06b0dd3 100644
--- a/mix.exs
+++ b/mix.exs
@@ -67,7 +67,11 @@ defmodule MyApp.MixProject do
{:dns_cluster, "~> 0.2.0"},
{:bandit, "~> 1.5"},
{:phoenix_test, "~> 0.7", only: :test, runtime: false},
- {:phoenix_test_playwright, "~> 0.9", only: :test, runtime: false}
+ {:phoenix_test_playwright,
+ github: "nathanl/phoenix_test_playwright",
+ ref: "sandbox_owner",
+ only: :test,
+ runtime: false}
]
end
diff --git a/mix.lock b/mix.lock
index 03247e2..c3a181d 100644
--- a/mix.lock
+++ b/mix.lock
@@ -35,7 +35,7 @@
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.2.0", "ff3a5616e1bed6804de7773b92cbccfc0b0f473faf1f63d7daf1206c7aeaaa6f", [:mix], [], "hexpm", "adc313a5bf7136039f63cfd9668fde73bba0765e0614cba80c06ac9460ff3e96"},
"phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"},
"phoenix_test": {:hex, :phoenix_test, "0.9.0", "0349496d868e53f2c776abe59204b09b2484475f97e3be7e9c9dcdd26f343551", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:lazy_html, "~> 0.1.7", [hex: :lazy_html, repo: "hexpm", optional: false]}, {:mime, ">= 1.0.0", [hex: :mime, repo: "hexpm", optional: true]}, {:phoenix, ">= 1.7.10", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "c214433a6c14746a0b58985653a72cdf1f19084c60f1ea2c8b8c4e0c809ec9f2"},
- "phoenix_test_playwright": {:hex, :phoenix_test_playwright, "0.9.1", "deac9b101ab506cdc04cad3bedfb7ec99753418fbab68fd63214126dcf92bc5c", [:mix], [{:ecto_sql, "~> 3.10", [hex: :ecto_sql, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.7", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_ecto, "~> 4.5", [hex: :phoenix_ecto, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 1.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_test, "~> 0.8", [hex: :phoenix_test, repo: "hexpm", optional: false]}], "hexpm", "82ebcb8cd8926a8d9054b9ff44c99991f0fa2247b4fc1434369f50f8e0913bfc"},
+ "phoenix_test_playwright": {:git, "https://github.com/nathanl/phoenix_test_playwright.git", "fe1da3095c26499d032b9111174a8c091966584c", [ref: "sandbox_owner"]},
"plug": {:hex, :plug, "1.18.1", "5067f26f7745b7e31bc3368bc1a2b818b9779faa959b49c934c17730efc911cf", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "57a57db70df2b422b564437d2d33cf8d33cd16339c1edb190cd11b1a3a546cc2"},
"plug_crypto": {:hex, :plug_crypto, "2.1.1", "19bda8184399cb24afa10be734f84a16ea0a2bc65054e23a62bb10f06bc89491", [:mix], [], "hexpm", "6470bce6ffe41c8bd497612ffde1a7e4af67f36a15eea5f921af71cf3e11247c"},
"postgrex": {:hex, :postgrex, "0.21.1", "2c5cc830ec11e7a0067dd4d623c049b3ef807e9507a424985b8dcf921224cd88", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "27d8d21c103c3cc68851b533ff99eef353e6a0ff98dc444ea751de43eb48bdac"},
diff --git a/test/features/register_test.exs b/test/features/register_test.exs
index fd4e0e5..b697516 100644
--- a/test/features/register_test.exs
+++ b/test/features/register_test.exs
@@ -1,25 +1,28 @@
defmodule Features.RegisterTest do
- use PhoenixTest.Playwright.Case, async: true
+ use PhoenixTest.Playwright.Case, async: true, parameterize: Enum.map(1..10, &%{param: &1})
use MyAppWeb, :verified_routes
- if !System.get_env("CI"), do: @tag(trace: :open)
+ # if !System.get_env("CI"), do: @tag(trace: :open)
- test "register", %{conn: conn} do
- conn
- |> visit(~p"/")
- |> click_link("Register")
- |> assert_has("body .phx-connected")
- |> fill_in("Email", with: "f@ftes.de")
- |> click_button("Create an account")
- |> assert_has("#flash-info", text: "email was sent")
- |> visit(~p"/dev/mailbox")
- |> click_link("log-in")
- |> click_button("Confirm and stay logged in")
- |> assert_has("#flash-info", text: "User confirmed")
- |> visit(~p"/users/settings")
- |> assert_has(".phx-connected")
- |> assert_has("h1", text: "Settings")
- |> visit(~p"/queries")
- |> assert_has("h1", text: "Database Queries")
+ for i <- 1..4 do
+ # @tag sandbox_shutdown_delay: 200
+ test "register #{i}", %{conn: conn} do
+ conn
+ |> visit(~p"/")
+ |> click_link("Register")
+ |> assert_has("body .phx-connected")
+ |> fill_in("Email", with: "f@ftes.de")
+ |> click_button("Create an account")
+ |> assert_has("#flash-info", text: "email was sent")
+ |> visit(~p"/dev/mailbox")
+ |> click_link("log-in")
+ |> click_button("Confirm and stay logged in")
+ |> assert_has("#flash-info", text: "User confirmed")
+ |> visit(~p"/users/settings")
+ |> assert_has(".phx-connected")
+ |> assert_has("h1", text: "Settings")
+ |> visit(~p"/queries")
+ |> assert_has("h1", text: "Database Queries")
+ end
end
end
I observe:
|
|
Thanks for the additional info. I need to do some more tinkering and thinking to understand that. |
|
Thanks for bearing with me Nathan. And for the effort you're putting into this. I'm just trying to make sure we end up with a good solution. And ideally have a test bed (either manually via this example app, or better yet we can translate our findings here into automated integration tests in the library). |
|
@ftes I don't fully understand those errors, but having locally added more labels and inspections, it seems to me that somehow they're coming from a db checkout that's done in the registration liveview, not one done by Furthermore, if I switch back to using the released version of |
|
It seems to me that |
|
I'm not sure how to test this change better than the demo at the top. We want to see what does or doesn't get logged after the test completes, so inherently the test itself can't assert that. I feel a bit stuck. These changes definitely improve the situation for the app I'm working on. I get why you want a more general proof and a way to prevent regression. But at the moment I'm not sure how to provide that better than this PR. |
|
Thanks for all the hard work Nathan. |
|
I've added some ecto based test to ftes/phoenix_test based on your examples here. Closing this. |
Builds on #4
Adds a demo page for Better sandbox lifecycle management.
Instructions:
mix test test/featuresas usual - should passQUERY_DELAY=100 mix test test/features- the test passes because it doesn't try to verify the results of the delayed async operation, but errors appear in the log when that operation attempts to use the sandbox after its owner (the test process) has shut downmix.exsat the branch in Better sandbox lifecycle management phoenix_test_playwright#95,mix deps.update, and add@tag sandbox_shutdown_delay: 200above the test. The error logs do not appear because the sandbox shutdown is delayed long enough for queries to finish.