From 1804a0a26a0a5300d3a18ec822641cf754de6a7e Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 1 May 2026 13:51:23 -0500 Subject: [PATCH] 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. --- lib/towerops/profiles/yaml_profiles.ex | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/towerops/profiles/yaml_profiles.ex b/lib/towerops/profiles/yaml_profiles.ex index b32309fc..1920d184 100644 --- a/lib/towerops/profiles/yaml_profiles.ex +++ b/lib/towerops/profiles/yaml_profiles.ex @@ -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