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.
This commit is contained in:
Graham McIntire 2025-10-25 17:41:58 -05:00
parent d896f65d15
commit 2a310c6685
No known key found for this signature in database
6 changed files with 23 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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)}")

View file

@ -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