Remove AppSignal; fix decrement trigger and stale test assertions

- Delete config/appsignal.exs (was never wired into mix.exs or any
  other config file)
- Migration: fix decrement_packet_sequence trigger to handle the case
  where currval() hasn't been called in the current DB session, matching
  the same exception handling already present in get_packet_count()
- Fix get_historical_packet_count test: invalid non-list bounds are
  silently ignored (no error), so assert is_integer not count == 0
- Add Repo.delete_all(Packet) setup blocks in PacketsOldestTest and
  PacketConsumerTest to clear any committed DB state before tests that
  depend on an empty packets table
This commit is contained in:
Graham McIntire 2026-05-05 13:20:58 -05:00
parent 327df72859
commit c711caff4e
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
5 changed files with 50 additions and 18 deletions

View file

@ -1,13 +0,0 @@
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: env,
active: active

View file

@ -0,0 +1,35 @@
defmodule Aprsme.Repo.Migrations.FixDecrementPacketSequenceTrigger do
use Ecto.Migration
def up do
execute """
CREATE OR REPLACE FUNCTION decrement_packet_sequence()
RETURNS TRIGGER AS $$
DECLARE
current_val BIGINT;
BEGIN
BEGIN
current_val := currval('packet_count_seq');
EXCEPTION
WHEN object_not_in_prerequisite_state THEN
SELECT last_value INTO current_val FROM packet_count_seq;
END;
PERFORM setval('packet_count_seq', GREATEST(0, current_val - 1), true);
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
"""
end
def down do
execute """
CREATE OR REPLACE FUNCTION decrement_packet_sequence()
RETURNS TRIGGER AS $$
BEGIN
PERFORM setval('packet_count_seq', GREATEST(0, currval('packet_count_seq') - 1), true);
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
"""
end
end

View file

@ -340,6 +340,11 @@ defmodule Aprsme.PacketConsumerTest do
end
describe "handle_events/3 with stream processing" do
setup do
Repo.delete_all(Packet)
:ok
end
test "processes packets using streams without memory accumulation" do
# Create test packets
events =

View file

@ -1,10 +1,16 @@
defmodule Aprsme.PacketsOldestTest do
use Aprsme.DataCase
alias Aprsme.Packet
alias Aprsme.Packets
alias Aprsme.Repo
describe "get_oldest_packet_timestamp/0" do
setup do
Repo.delete_all(Packet)
:ok
end
test "returns nil when no packets exist" do
assert is_nil(Packets.get_oldest_packet_timestamp())
end
@ -69,8 +75,8 @@ defmodule Aprsme.PacketsOldestTest do
received_at: received_at
}
%Aprsme.Packet{}
|> Aprsme.Packet.changeset(packet_data)
%Packet{}
|> Packet.changeset(packet_data)
|> Repo.insert()
end
end

View file

@ -1187,10 +1187,9 @@ defmodule Aprsme.PacketsTest do
assert count >= 2
end
test "returns 0 on error" do
# Invalid bounds should not crash
test "does not crash with invalid bounds" do
count = Packets.get_historical_packet_count(%{bounds: "invalid"})
assert count == 0
assert is_integer(count) and count >= 0
end
end