fix(test): load YAML profiles synchronously in test env

The deferred load via send(self(), :load_profiles) is fine in dev/prod
where SNMP polling starts well after boot, but it races with tests that
exercise discovery immediately after the GenServer starts. With an empty
ETS table, match_profile/2 returns nil and discovery falls back to the
Base profile, breaking tests that rely on YAML-profile-derived
manufacturer strings.
This commit is contained in:
Graham McIntire 2026-05-01 13:51:23 -05:00
parent 012899792e
commit 1804a0a26a

View file

@ -88,10 +88,19 @@ defmodule Towerops.Profiles.YamlProfiles do
@impl true
def init(_opts) do
_ = :ets.new(@table, [:named_table, :set, :public, read_concurrency: true])
# Defer loading so the supervisor (and Bandit) start immediately.
# Profiles will be available within ~60s; SNMP polling starts well after that.
send(self(), :load_profiles)
{:ok, %{}}
if Mix.env() == :test do
# Load synchronously so tests don't race with deferred loading.
raw_profiles = load_all_profiles()
mib_names = extract_mib_names_from_profiles(raw_profiles)
MibCache.pre_resolve(mib_names)
{:ok, %{}}
else
# Defer loading so the supervisor (and Bandit) start immediately.
# Profiles will be available within ~60s; SNMP polling starts well after that.
send(self(), :load_profiles)
{:ok, %{}}
end
end
@impl true