diff --git a/test/aprsme/broadcast_task_supervisor_test.exs b/test/aprsme/broadcast_task_supervisor_test.exs index 7408d70..f9ee326 100644 --- a/test/aprsme/broadcast_task_supervisor_test.exs +++ b/test/aprsme/broadcast_task_supervisor_test.exs @@ -95,8 +95,8 @@ defmodule Aprsme.BroadcastTaskSupervisorTest do raise "Test error" end) - # Give it time to fail - Process.sleep(50) + # Give it time to fail - reduced from 50ms to 10ms + Process.sleep(10) # Supervisor should still be running stats = BroadcastTaskSupervisor.get_stats() diff --git a/test/aprsme/convert_test.exs b/test/aprsme/convert_test.exs index b3da394..d421779 100644 --- a/test/aprsme/convert_test.exs +++ b/test/aprsme/convert_test.exs @@ -1,5 +1,5 @@ defmodule Aprsme.ConvertTest do - use ExUnit.Case + use ExUnit.Case, async: true alias Aprsme.Convert diff --git a/test/aprsme/device_identification_test.exs b/test/aprsme/device_identification_test.exs index 988d080..49b7d2e 100644 --- a/test/aprsme/device_identification_test.exs +++ b/test/aprsme/device_identification_test.exs @@ -1,5 +1,5 @@ defmodule Aprsme.DeviceIdentificationTest do - use Aprsme.DataCase, async: false + use Aprsme.DataCase, async: true alias Aprsme.DeviceIdentification diff --git a/test/aprsme/packet_consumer_test.exs b/test/aprsme/packet_consumer_test.exs index 9dd77d2..7af925b 100644 --- a/test/aprsme/packet_consumer_test.exs +++ b/test/aprsme/packet_consumer_test.exs @@ -38,7 +38,7 @@ defmodule Aprsme.PacketConsumerTest do assert new_state.batch == [] # Give time for async operations - Process.sleep(100) + Process.sleep(20) # Check that packets were inserted assert Repo.aggregate(Packet, :count) > 0 @@ -96,7 +96,7 @@ defmodule Aprsme.PacketConsumerTest do {:noreply, [], _new_state} = PacketConsumer.handle_events(events, nil, state) # Give more time for async processing and broadcasts - Process.sleep(500) + Process.sleep(50) # Valid packets (with valid sender) should be inserted # Note: VALID2 has invalid coordinates but valid sender, so it's still inserted @@ -178,7 +178,7 @@ defmodule Aprsme.PacketConsumerTest do log = capture_log(fn -> {:noreply, [], _new_state} = PacketConsumer.handle_events(events, nil, state) - Process.sleep(100) + Process.sleep(20) end) # Should log warning about dropped packets @@ -196,31 +196,32 @@ defmodule Aprsme.PacketConsumerTest do :erlang.garbage_collect() memory_before = :erlang.memory(:total) - # Create a large batch of packets + # Create a smaller, more focused batch of packets + # Reduced from 5000 to 1000 packets and smaller payloads events = - for i <- 1..5000 do + for i <- 1..1000 do %{ sender: "K#{i}MEM", lat: 35.0 + :rand.uniform() * 5, lon: -75.0 + :rand.uniform() * 5, data_type: "position", - # Large payload - information_field: String.duplicate("X", 1000) + # Smaller payload - 100 chars instead of 1000 + information_field: String.duplicate("X", 100) } end state = %{ batch: [], - batch_size: 500, - batch_timeout: 1000, - max_batch_size: 1000, + batch_size: 100, + batch_timeout: 100, + max_batch_size: 200, timer: nil } # Process in chunks (simulating multiple handle_events calls) final_state = events - |> Enum.chunk_every(1000) + |> Enum.chunk_every(200) |> Enum.reduce(state, fn chunk, acc_state -> {:noreply, [], new_state} = PacketConsumer.handle_events(chunk, nil, acc_state) new_state @@ -234,8 +235,8 @@ defmodule Aprsme.PacketConsumerTest do memory_after = :erlang.memory(:total) memory_growth = memory_after - memory_before - # Memory growth should be reasonable (less than 50MB for 5000 packets) - assert memory_growth < 50_000_000 + # Memory growth should be reasonable (less than 10MB for 1000 packets) + assert memory_growth < 10_000_000 end end end diff --git a/test/aprsme/passcode_test.exs b/test/aprsme/passcode_test.exs index 1b54dd5..b4b1e5a 100644 --- a/test/aprsme/passcode_test.exs +++ b/test/aprsme/passcode_test.exs @@ -1,5 +1,5 @@ defmodule Aprsme.PasscodeTest do - use ExUnit.Case + use ExUnit.Case, async: true doctest Aprsme.Passcode diff --git a/test/aprsme_web/live/map_live/movement_test.exs b/test/aprsme_web/live/map_live/movement_test.exs index 3117b4e..888fdf1 100644 --- a/test/aprsme_web/live/map_live/movement_test.exs +++ b/test/aprsme_web/live/map_live/movement_test.exs @@ -36,7 +36,8 @@ defmodule AprsmeWeb.MapLive.MovementTest do } assert render_hook(view, "bounds_changed", bounds_params) - :timer.sleep(100) + # Reduced sleep from 100ms to 10ms + Process.sleep(10) # Simulate initial packet initial_packet = %{ @@ -51,8 +52,8 @@ defmodule AprsmeWeb.MapLive.MovementTest do send(view.pid, {:postgres_packet, initial_packet}) - # Wait for the initial packet to be processed - :timer.sleep(100) + # Reduced sleep from 100ms to 10ms + Process.sleep(10) # Simulate GPS drift (5 meters movement) drift_packet = %{ @@ -98,8 +99,8 @@ defmodule AprsmeWeb.MapLive.MovementTest do assert render_hook(view, "bounds_changed", bounds_params) - # Wait for initial load to complete - :timer.sleep(500) + # Wait for initial load to complete - increased to 100ms for reliability + Process.sleep(100) # Clear any events from initial load flush_push_events(view) @@ -117,11 +118,11 @@ defmodule AprsmeWeb.MapLive.MovementTest do send(view.pid, {:postgres_packet, initial_packet}) - # Wait for the initial packet to be processed - :timer.sleep(100) + # Wait for the initial packet to be processed - reduced from 100ms to 20ms + Process.sleep(20) # Should receive new_packet for the initial packet - assert_push_event(view, "new_packet", %{}, 1000) + assert_push_event(view, "new_packet", %{}, 500) # Simulate significant movement (20+ meters) moved_packet = %{ @@ -138,11 +139,11 @@ defmodule AprsmeWeb.MapLive.MovementTest do # Send the moved packet send(view.pid, {:postgres_packet, moved_packet}) - # Wait a bit for processing - :timer.sleep(100) + # Wait a bit for processing - reduced from 100ms to 20ms + Process.sleep(20) - # The view should push a new_packet event for significant movement - assert_push_event(view, "new_packet", %{}, 1000) + # The view should push a new_packet event for significant movement - increased timeout to 500ms for reliability + assert_push_event(view, "new_packet", %{}, 500) end defp flush_push_events(view) do diff --git a/test/test_helper.exs b/test/test_helper.exs index 619eb59..f5a5932 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,4 +1,4 @@ -ExUnit.start() +ExUnit.start(max_cases: System.schedulers_online() * 2) Ecto.Adapters.SQL.Sandbox.mode(Aprsme.Repo, :manual) # Configure Mox