diff --git a/.test-commands b/.test-commands new file mode 100644 index 0000000..50c81fe --- /dev/null +++ b/.test-commands @@ -0,0 +1,19 @@ +# Fast Test Commands + +# Run only fast tests (excludes slow and integration tests) +alias test-fast="mix test --exclude slow --exclude integration" + +# Run all tests including slow ones +alias test-all="mix test" + +# Run tests with coverage (slower) +alias test-cover="mix test --cover" + +# Run tests continuously during development +alias test-watch="mix test.watch --exclude slow --exclude integration" + +# Run only failing tests +alias test-failed="mix test --failed" + +# Run stale tests (only tests affected by code changes) +alias test-stale="mix test --stale --exclude slow --exclude integration" \ No newline at end of file diff --git a/config/test.exs b/config/test.exs index 4c6d4bc..af0c485 100644 --- a/config/test.exs +++ b/config/test.exs @@ -14,10 +14,12 @@ config :aprsme, Aprsme.Repo, hostname: "localhost", database: "aprsme_test#{System.get_env("MIX_TEST_PARTITION")}", pool: Ecto.Adapters.SQL.Sandbox, - pool_size: System.schedulers_online() * 2, + pool_size: System.schedulers_online() * 4, types: Aprsme.PostgresTypes, - ownership_timeout: 300_000, - timeout: 300_000 + ownership_timeout: 60_000, + timeout: 15_000, + queue_target: 50, + queue_interval: 100 # We don't run a server during test. If one is required, # you can enable the server option below. @@ -74,8 +76,8 @@ config :exvcr, config :hammer, backend: {Hammer.Backend.ETS, [expiry_ms: 60_000 * 60 * 4, cleanup_interval_ms: 60_000 * 10]} -# Print only warnings and errors during test -config :logger, level: :warning +# Disable logging during test for better performance +config :logger, level: :error # Initialize plugs at runtime for faster test compilation config :phoenix, :plug_init_mode, :runtime diff --git a/test/aprsme/cluster/leader_election_test.exs b/test/aprsme/cluster/leader_election_test.exs index c965c9b..8da1097 100644 --- a/test/aprsme/cluster/leader_election_test.exs +++ b/test/aprsme/cluster/leader_election_test.exs @@ -140,6 +140,7 @@ defmodule Aprsme.Cluster.LeaderElectionTest do assert :global.whereis_name(@election_key) == :undefined end + @tag :slow test "periodic leadership check continues running" do {:ok, _pid} = LeaderElection.start_link([]) @@ -185,18 +186,22 @@ defmodule Aprsme.Cluster.LeaderElectionTest do end describe "stale registration cleanup" do + @tag :slow test "cleans up registration when process dies" do # Register a dead process dead_pid = spawn(fn -> :ok end) # Ensure it's dead - Process.sleep(10) + Process.sleep(50) # Force register it globally (simulating stale registration) :global.re_register_name(@election_key, dead_pid) # Start LeaderElection which should clean it up + Application.put_env(:aprsme, :cluster_enabled, false) {:ok, _pid} = LeaderElection.start_link([]) - Process.sleep(200) + + # Wait longer for cleanup and election to occur + Process.sleep(500) # Should have taken over leadership assert LeaderElection.is_leader?() == true @@ -209,6 +214,7 @@ defmodule Aprsme.Cluster.LeaderElectionTest do :ok end + @tag :slow test "waits for cluster formation when enabled" do {:ok, _pid} = LeaderElection.start_link([]) diff --git a/test/aprsme/packet_consumer_test.exs b/test/aprsme/packet_consumer_test.exs index 7af925b..401567d 100644 --- a/test/aprsme/packet_consumer_test.exs +++ b/test/aprsme/packet_consumer_test.exs @@ -154,6 +154,9 @@ defmodule Aprsme.PacketConsumerTest do test "respects max_batch_size and drops excess packets" do import ExUnit.CaptureLog + + # Temporarily enable warning level for this test + Logger.configure(level: :warning) # Create more packets than max_batch_size events = for i <- 1..150 do @@ -183,6 +186,9 @@ defmodule Aprsme.PacketConsumerTest do # Should log warning about dropped packets assert log =~ "Dropped 50 packets due to batch size limit" + + # Reset log level + Logger.configure(level: :error) # Only max_batch_size packets should be processed packet_count = Repo.aggregate(Packet, :count) diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 806d7f2..07faa1f 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -37,7 +37,10 @@ defmodule Aprsme.DataCase do setup tags do Aprsme.DataCase.setup_sandbox(tags) - Aprsme.DevicesSeeder.seed_from_json() + # Only seed devices for tests that need them + if tags[:needs_devices] do + Aprsme.DevicesSeeder.seed_from_json() + end :ok end diff --git a/test/test_helper.exs b/test/test_helper.exs index e01b556..1db19c1 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,4 +1,9 @@ -ExUnit.start(max_cases: System.schedulers_online() * 2) +ExUnit.start( + max_cases: System.schedulers_online() * 4, + timeout: 30_000, + capture_log: true, + exclude: [:slow, :integration] +) Ecto.Adapters.SQL.Sandbox.mode(Aprsme.Repo, :manual) # Configure Mox