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:
parent
327df72859
commit
c711caff4e
5 changed files with 50 additions and 18 deletions
|
|
@ -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
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -340,6 +340,11 @@ defmodule Aprsme.PacketConsumerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "handle_events/3 with stream processing" do
|
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
|
test "processes packets using streams without memory accumulation" do
|
||||||
# Create test packets
|
# Create test packets
|
||||||
events =
|
events =
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
defmodule Aprsme.PacketsOldestTest do
|
defmodule Aprsme.PacketsOldestTest do
|
||||||
use Aprsme.DataCase
|
use Aprsme.DataCase
|
||||||
|
|
||||||
|
alias Aprsme.Packet
|
||||||
alias Aprsme.Packets
|
alias Aprsme.Packets
|
||||||
alias Aprsme.Repo
|
alias Aprsme.Repo
|
||||||
|
|
||||||
describe "get_oldest_packet_timestamp/0" do
|
describe "get_oldest_packet_timestamp/0" do
|
||||||
|
setup do
|
||||||
|
Repo.delete_all(Packet)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "returns nil when no packets exist" do
|
test "returns nil when no packets exist" do
|
||||||
assert is_nil(Packets.get_oldest_packet_timestamp())
|
assert is_nil(Packets.get_oldest_packet_timestamp())
|
||||||
end
|
end
|
||||||
|
|
@ -69,8 +75,8 @@ defmodule Aprsme.PacketsOldestTest do
|
||||||
received_at: received_at
|
received_at: received_at
|
||||||
}
|
}
|
||||||
|
|
||||||
%Aprsme.Packet{}
|
%Packet{}
|
||||||
|> Aprsme.Packet.changeset(packet_data)
|
|> Packet.changeset(packet_data)
|
||||||
|> Repo.insert()
|
|> Repo.insert()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1187,10 +1187,9 @@ defmodule Aprsme.PacketsTest do
|
||||||
assert count >= 2
|
assert count >= 2
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 0 on error" do
|
test "does not crash with invalid bounds" do
|
||||||
# Invalid bounds should not crash
|
|
||||||
count = Packets.get_historical_packet_count(%{bounds: "invalid"})
|
count = Packets.get_historical_packet_count(%{bounds: "invalid"})
|
||||||
assert count == 0
|
assert is_integer(count) and count >= 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue