Minor test refactoring to improve on performance closes #383 #384

Merged
simon merged 23 commits from test-performance-optimization into main 2026-01-29 15:44:01 +01:00
Showing only changes of commit 6efad280bd - Show all commits

View file

@ -31,7 +31,10 @@ defmodule Mv.SeedsTest do
setup do setup do
system_actor = Mv.Helpers.SystemActor.get_system_actor() system_actor = Mv.Helpers.SystemActor.get_system_actor()
# Run seeds only once per test run (check process dictionary) # Run seeds once per test process (due to sandbox isolation, each test runs in its own process)
# Process.get/put ensures seeds are only executed once per test process, not once per test
# Note: With async: false and sandbox isolation, this effectively runs seeds once per test,
# but the guard prevents multiple executions within the same test process if setup is called multiple times
unless Process.get(@seeds_run_key) do unless Process.get(@seeds_run_key) do
Code.eval_file("priv/repo/seeds.exs") Code.eval_file("priv/repo/seeds.exs")
Process.put(@seeds_run_key, true) Process.put(@seeds_run_key, true)
@ -55,7 +58,7 @@ defmodule Mv.SeedsTest do
end end
test "is idempotent when run multiple times", %{actor: actor} do test "is idempotent when run multiple times", %{actor: actor} do
# Seeds already run once in setup_all - count current state # Seeds already run once in setup - count current state
{:ok, users_count_1} = Ash.read(Mv.Accounts.User, actor: actor) {:ok, users_count_1} = Ash.read(Mv.Accounts.User, actor: actor)
{:ok, members_count_1} = Ash.read(Mv.Membership.Member, actor: actor) {:ok, members_count_1} = Ash.read(Mv.Membership.Member, actor: actor)