From 61b492e93b4a0f449330bfa2682fe725e62dd9db Mon Sep 17 00:00:00 2001 From: rcourtman Date: Thu, 16 Oct 2025 08:28:17 +0000 Subject: [PATCH] Fix race in mock mode and address frontend type checks --- .../pages/__tests__/Alerts.helpers.test.ts | 12 +++++----- internal/mock/integration.go | 22 ++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/frontend-modern/src/pages/__tests__/Alerts.helpers.test.ts b/frontend-modern/src/pages/__tests__/Alerts.helpers.test.ts index c0b84a0..36c838e 100644 --- a/frontend-modern/src/pages/__tests__/Alerts.helpers.test.ts +++ b/frontend-modern/src/pages/__tests__/Alerts.helpers.test.ts @@ -12,11 +12,11 @@ import { pathForTab, tabFromPath, } from '../Alerts'; +import type { RawOverrideConfig } from '@/types/alerts'; describe('normalizeMetricDelayMap', () => { it('returns empty object when input is nullish', () => { expect(normalizeMetricDelayMap(undefined)).toEqual({}); - // @ts-expect-error - testing runtime null handling expect(normalizeMetricDelayMap(null)).toEqual({}); }); @@ -139,17 +139,19 @@ describe('threshold helper utilities', () => { it('extracts trigger values and ignores non-threshold keys', () => { const result = extractTriggerValues({ cpu: { trigger: 80, clear: 70 }, - memory: 85, + memory: { trigger: 85, clear: 75 }, disabled: true, poweredOffSeverity: 'warning', - networkIn: false, + customFlag: true, + customLegacy: 42, label: 'ignored', - }); + } as RawOverrideConfig); expect(result).toEqual({ cpu: 80, memory: 85, - networkIn: 0, + customFlag: 0, + customLegacy: 42, }); }); diff --git a/internal/mock/integration.go b/internal/mock/integration.go index c48d4b7..8205873 100644 --- a/internal/mock/integration.go +++ b/internal/mock/integration.go @@ -120,29 +120,31 @@ func disableMockMode() { func startUpdateLoopLocked() { stopUpdateLoopLocked() - stopUpdatesCh = make(chan struct{}) - updateTicker = time.NewTicker(updateInterval) + stopCh := make(chan struct{}) + ticker := time.NewTicker(updateInterval) + stopUpdatesCh = stopCh + updateTicker = ticker - go func() { + go func(stop <-chan struct{}, tick *time.Ticker) { for { select { - case <-updateTicker.C: + case <-tick.C: cfg := GetConfig() updateMetrics(cfg) - case <-stopUpdatesCh: + case <-stop: return } } - }() + }(stopCh, ticker) } func stopUpdateLoopLocked() { - if updateTicker != nil { - updateTicker.Stop() + if ticker := updateTicker; ticker != nil { + ticker.Stop() updateTicker = nil } - if stopUpdatesCh != nil { - close(stopUpdatesCh) + if ch := stopUpdatesCh; ch != nil { + close(ch) stopUpdatesCh = nil } }