Fix race in mock mode and address frontend type checks
This commit is contained in:
parent
6fdef61710
commit
61b492e93b
2 changed files with 19 additions and 15 deletions
|
|
@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue