Guard NewWSHub nil-db path to fix test suite flake

This commit is contained in:
AetherForge
2026-06-02 22:02:34 -07:00
parent 60ab286403
commit 96f683a72a

View File

@@ -121,9 +121,11 @@ type WSHub struct {
func NewWSHub(database *db.Database) *WSHub { func NewWSHub(database *db.Database) *WSHub {
// Reset any rows that were left "online" by a previous server crash/restart. // Reset any rows that were left "online" by a previous server crash/restart.
// Agents will re-authenticate and flip themselves back to online within seconds. // Agents will re-authenticate and flip themselves back to online within seconds.
if database != nil {
if err := database.MarkAllAgentsOffline(); err != nil { if err := database.MarkAllAgentsOffline(); err != nil {
log.Printf("[hub] startup offline reset: %v", err) log.Printf("[hub] startup offline reset: %v", err)
} }
}
h := &WSHub{ h := &WSHub{
db: database, db: database,
@@ -148,6 +150,9 @@ func NewWSHub(database *db.Database) *WSHub {
// last_seen timestamp is stale (> 3 minutes without a stats message). // last_seen timestamp is stale (> 3 minutes without a stats message).
// It also notifies the dashboard so client state stays in sync. // It also notifies the dashboard so client state stays in sync.
func (h *WSHub) runStaleAgentSweep() { func (h *WSHub) runStaleAgentSweep() {
if h.db == nil {
return
}
const staleness = 3 * time.Minute const staleness = 3 * time.Minute
ticker := time.NewTicker(45 * time.Second) ticker := time.NewTicker(45 * time.Second)
defer ticker.Stop() defer ticker.Stop()