test(server): stop leaked fixtures from polluting later tests

TestMgmtAPI never closed its manager, so the notifier and task-archive workers started by New(context.Background()) kept claiming other tests digest batches and archive jobs. TestTaskOutcomeCard left a skill_usage miss row behind (the table has no foreign keys), which outranked TestSkillGapsReport fixture from the fourth -count iteration on.
This commit is contained in:
BaaRai
2026-11-14 15:44:52 +01:00
parent ae792126dc
commit 5cdb720122
2 changed files with 7 additions and 0 deletions
+4
View File
@@ -18,6 +18,10 @@ func TestMgmtAPI(t *testing.T) {
if m.pg == nil {
t.Skip("postgres unavailable — skipping management API test")
}
// New starts the notifier and task-archive workers on context.Background();
// closing the pool stops them from claiming later tests' digest batches
// and archive jobs.
defer m.Close()
td := t.TempDir()
s := New(context.Background(), m, td, td, td)
h := s.Handler()
+3
View File
@@ -23,6 +23,9 @@ func TestTaskOutcomeCard(t *testing.T) {
}
taskID, _ := strconv.ParseInt(task.ID, 10, 64)
defer func() { _ = m.pg.DeleteTask(taskID) }()
// skill_usage has no foreign keys, so DeleteTask leaves these rows behind,
// and their misses would outrank TestSkillGapsReport's fixture in later runs.
defer func() { _, _ = m.pg.Exec(`DELETE FROM skill_usage WHERE task_id=$1`, taskID) }()
if _, err := m.pg.Exec(`
INSERT INTO findings(task_id,vulnclass,name,severity,status) VALUES