From 2a310c6685005cb9120c436c757483f1dcbc2562 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 25 Oct 2025 17:41:58 -0500 Subject: [PATCH] Fix test warnings and failures - Add Phoenix.LiveViewTest import to ConnCase to fix warnings - Disable AppSignal in dev and test (only enable in prod) - Explicitly disable clustering in test environment - Fix PacketDistributor to check cluster_enabled before calling LeaderElection - Add Phoenix.CodeReloader listener to mix.exs This prevents tests from trying to call cluster-specific GenServers (ConnectionMonitor, LeaderElection) that don't exist in test mode. --- config/appsignal.exs | 8 +++++++- config/dev.exs | 2 -- config/test.exs | 5 +++-- lib/aprsme/cluster/packet_distributor.ex | 6 ++++-- lib/aprsme_web/channels/mobile_channel.ex | 8 +++++++- test/support/conn_case.ex | 3 ++- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/config/appsignal.exs b/config/appsignal.exs index a530c16..cbb4d82 100644 --- a/config/appsignal.exs +++ b/config/appsignal.exs @@ -1,7 +1,13 @@ import Config +# Only enable AppSignal in production +# Use config_env() which is available at runtime +env = config_env() +active = env == :prod + config :appsignal, :config, otp_app: :aprsme, name: "aprsme", push_api_key: "070601ca-6102-4214-82ad-d0c40df7f6ee", - env: Mix.env() + env: env, + active: active diff --git a/config/dev.exs b/config/dev.exs index 471555e..8d1cc71 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,7 +1,5 @@ import Config -config :appsignal, :config, active: true - # Configure your database config :aprsme, Aprsme.Repo, # For development, we disable any cache and enable diff --git a/config/test.exs b/config/test.exs index a52476c..8b1e927 100644 --- a/config/test.exs +++ b/config/test.exs @@ -41,14 +41,15 @@ config :aprsme, :initialize_replay_delay, 0 # Configure the packets module to use the mock in tests config :aprsme, :packets_module, Aprsme.PacketsMock -# Disable APRS-IS external connections in test environment +# Disable APRS-IS external connections and clustering in test environment config :aprsme, aprs_is_server: "mock.aprs.test", aprs_is_port: 14_580, aprs_is_default_filter: "r/33/-96/100", aprs_is_login_id: "TEST", aprs_is_password: "-1", - disable_aprs_connection: true + disable_aprs_connection: true, + cluster_enabled: false # Disable automatic migrations during tests config :aprsme, auto_migrate: false diff --git a/lib/aprsme/cluster/packet_distributor.ex b/lib/aprsme/cluster/packet_distributor.ex index 2e97eda..00136cf 100644 --- a/lib/aprsme/cluster/packet_distributor.ex +++ b/lib/aprsme/cluster/packet_distributor.ex @@ -9,8 +9,10 @@ defmodule Aprsme.Cluster.PacketDistributor do @pubsub_topic "cluster:packets" def distribute_packet(packet) do - # Only distribute if we're the leader - if Aprsme.Cluster.LeaderElection.is_leader?() do + # Only distribute if clustering is enabled and we're the leader + cluster_enabled = Application.get_env(:aprsme, :cluster_enabled, false) + + if cluster_enabled and Aprsme.Cluster.LeaderElection.is_leader?() do # Broadcast to all nodes including self Phoenix.PubSub.broadcast( Aprsme.PubSub, diff --git a/lib/aprsme_web/channels/mobile_channel.ex b/lib/aprsme_web/channels/mobile_channel.ex index 8404a5e..9dc15fb 100644 --- a/lib/aprsme_web/channels/mobile_channel.ex +++ b/lib/aprsme_web/channels/mobile_channel.ex @@ -385,6 +385,8 @@ defmodule AprsmeWeb.MobileChannel do # Normalize query to uppercase query = String.upcase(query) + Logger.info("Searching for callsign: #{query}") + # Build search pattern - support wildcard with * pattern = if String.contains?(query, "*") do @@ -395,6 +397,8 @@ defmodule AprsmeWeb.MobileChannel do "#{query}%" end + Logger.info("Search pattern: #{pattern}") + # Query for matching callsigns - optimized version # Use a subquery to get only the most recent packet per sender results = @@ -415,7 +419,9 @@ defmodule AprsmeWeb.MobileChannel do order_by: [desc: max(p.received_at)], limit: ^limit - Aprsme.Repo.all(subquery) + results = Aprsme.Repo.all(subquery) + Logger.info("Search returned #{length(results)} results: #{inspect(results)}") + results rescue error -> Logger.error("Error searching callsigns: #{inspect(error)}") diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index a3dba34..be0d068 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -25,6 +25,7 @@ defmodule AprsmeWeb.ConnCase do import Aprsme.MockHelpers import AprsmeWeb.ConnCase import Phoenix.ConnTest + import Phoenix.LiveViewTest import Plug.Conn alias Aprsme.Repo @@ -38,7 +39,7 @@ defmodule AprsmeWeb.ConnCase do # Helper for LiveView tests that may have duplicate IDs def live_with_warn(conn, path) do - Phoenix.LiveViewTest.live(conn, path, on_error: :warn) + live(conn, path, on_error: :warn) end end end