diff --git a/config/test.exs b/config/test.exs index af34913..1ff9eda 100644 --- a/config/test.exs +++ b/config/test.exs @@ -27,6 +27,9 @@ config :aprs, AprsWeb.Endpoint, # Disable Oban during tests to prevent background job execution config :aprs, Oban, testing: :inline +# Disable initialize replay delay in test environment +config :aprs, :initialize_replay_delay, 0 + # Configure the packets module to use the mock in tests config :aprs, :packets_module, Aprs.PacketsMock diff --git a/lib/aprs_web/live/map_live/index.ex b/lib/aprs_web/live/map_live/index.ex index 0aaf6d9..a770b62 100644 --- a/lib/aprs_web/live/map_live/index.ex +++ b/lib/aprs_web/live/map_live/index.ex @@ -12,6 +12,7 @@ defmodule AprsWeb.MapLive.Index do @default_center %{lat: 39.8283, lng: -98.5795} @default_zoom 5 @finch_name Aprs.Finch + @initialize_replay_delay Application.compile_env(:aprs, :initialize_replay_delay, 500) @impl true def mount(_params, _session, socket) do @@ -214,7 +215,7 @@ defmodule AprsWeb.MapLive.Index do socket = assign(socket, map_ready: true) # Start historical replay - Process.send_after(self(), :initialize_replay, 500) + Process.send_after(self(), :initialize_replay, @initialize_replay_delay) # If we have pending geolocation, zoom to it now socket = diff --git a/test/aprs_web/integration/aprs_status_test.exs b/test/aprs_web/integration/aprs_status_test.exs index 96fe57c..f499e8a 100644 --- a/test/aprs_web/integration/aprs_status_test.exs +++ b/test/aprs_web/integration/aprs_status_test.exs @@ -134,7 +134,7 @@ defmodule AprsWeb.Integration.AprsStatusTest do Endpoint.broadcast("aprs_messages", "packet", test_packet) # Give a moment for any potential updates - Process.sleep(100) + Process.sleep(5) # View should remain stable (no crashes from missing APRS connection) assert has_element?(view, "#aprs-map") diff --git a/test/aprs_web/live/map_live/index_test.exs b/test/aprs_web/live/map_live/index_test.exs index 641e519..2a94947 100644 --- a/test/aprs_web/live/map_live/index_test.exs +++ b/test/aprs_web/live/map_live/index_test.exs @@ -71,7 +71,7 @@ defmodule AprsWeb.MapLive.IndexTest do assert render_hook(view, "map_ready", %{}) # Wait for the initialize_replay message to be processed - Process.sleep(600) + Process.sleep(20) # The view should still be rendering without errors after loading historical packets assert render(view) =~ "aprs-map" diff --git a/test/integration/historical_packets_test.exs b/test/integration/historical_packets_test.exs index 79277f2..844debb 100644 --- a/test/integration/historical_packets_test.exs +++ b/test/integration/historical_packets_test.exs @@ -105,7 +105,7 @@ defmodule Aprs.Integration.HistoricalPacketsTest do # Set historical_hours assign render_hook(view, "update_historical_hours", %{"historical_hours" => "1"}) - Process.sleep(100) + Process.sleep(10) # Set bounds and wait for map_bounds to be set in assigns render_hook(view, "bounds_changed", bounds_params) @@ -121,11 +121,11 @@ defmodule Aprs.Integration.HistoricalPacketsTest do }} ) - Process.sleep(100) + Process.sleep(10) # Now trigger map_ready render_hook(view, "map_ready", %{}) - Process.sleep(1200) + Process.sleep(20) # The LiveView should have pushed an event with historical packets # Note: In real implementation, we'd need to verify the push_event was called @@ -153,7 +153,7 @@ defmodule Aprs.Integration.HistoricalPacketsTest do # Set historical_hours assign render_hook(view, "update_historical_hours", %{"historical_hours" => "1"}) - Process.sleep(100) + Process.sleep(10) # Set bounds and wait for map_bounds to be set in assigns render_hook(view, "bounds_changed", bounds_params) @@ -169,11 +169,11 @@ defmodule Aprs.Integration.HistoricalPacketsTest do }} ) - Process.sleep(100) + Process.sleep(10) # Now trigger map_ready render_hook(view, "map_ready", %{}) - Process.sleep(1200) + Process.sleep(20) verify!() end @@ -222,7 +222,7 @@ defmodule Aprs.Integration.HistoricalPacketsTest do # First load historical packets render_hook(view, "map_ready", %{}) - Process.sleep(700) + Process.sleep(20) # Clear and reload markers render_hook(view, "clear_and_reload_markers", %{}) @@ -240,7 +240,7 @@ defmodule Aprs.Integration.HistoricalPacketsTest do # Load historical packets first render_hook(view, "map_ready", %{}) - Process.sleep(700) + Process.sleep(20) # Request location render_hook(view, "locate_me", %{}) @@ -304,13 +304,13 @@ defmodule Aprs.Integration.HistoricalPacketsTest do }} ) - Process.sleep(100) + Process.sleep(10) render_hook(view, "map_ready", %{}) - Process.sleep(700) + Process.sleep(20) # Set historical_hours assign render_hook(view, "update_historical_hours", %{"historical_hours" => "1"}) - Process.sleep(100) + Process.sleep(5) # Simulate a new live packet for the same callsign new_packet = %{ @@ -341,7 +341,7 @@ defmodule Aprs.Integration.HistoricalPacketsTest do }) # Give the LiveView time to process the message - Process.sleep(100) + Process.sleep(5) verify!() end