Files
pulse/internal/mock/integration_shutdown_test.go
T
rcourtman b707512e38 Clear all errcheck and gofmt violations so make lint gates on real findings
golangci-lint run ./... failed on ~190 pre-existing errcheck violations and
5 unformatted files, burying any new regression in noise. Fix all of them:

- Test files that hand-rolled mock-mode set/restore (vmware, truenas, and
  friends) now use the canonical setMockModeForTest/testutil.SetMockMode
  helper instead of drift copies that ignored SetEnabled errors.
- internal/mock and internal/monitoring tests get package-local
  mustSetEnabled/mustSetMockEnabled/mustSetMonitorMockMode helpers that
  fail the test on toggle errors.
- pkg/auth/sqlite_manager.go, pkg/metrics/store.go, pkg/server/server.go:
  rollbacks in defers use the explicit-discard idiom, migration renames and
  rollup commits log failures, the hosted reaper goroutine logs an error
  exit, shutdown mock-disable logs failures.
- Remaining test sites check errors with t.Fatalf/t.Errorf or explicitly
  discard best-effort calls (restore-chmods, handler-closure unmarshals)
  per existing repo style.
- gofmt: internal/api/maintenance_verification.go, internal/ai/demo.go and
  three findings test files.

Only dupl findings remain (44 pre-existing production-code duplication
pairs) — those need real refactors, not mechanical fixes.

Full test suites pass for every touched package.
2026-06-09 21:42:21 +01:00

41 lines
771 B
Go

package mock
import (
"testing"
"time"
)
func TestSetEnabledDisableDoesNotDeadlockWhenLoopNeedsStateLock(t *testing.T) {
mustSetEnabled(t, false)
t.Cleanup(func() {
mustSetEnabled(t, false)
})
dataMu.Lock()
enabled.Store(true)
stopUpdatesCh = make(chan struct{})
updateTicker = time.NewTicker(time.Hour)
updateLoopWg.Add(1)
go func(stop <-chan struct{}) {
defer updateLoopWg.Done()
<-stop
dataMu.Lock()
dataMu.Unlock()
}(stopUpdatesCh)
dataMu.Unlock()
done := make(chan struct{})
go func() {
if err := SetEnabled(false); err != nil {
t.Errorf("SetEnabled(false): %v", err)
}
close(done)
}()
select {
case <-done:
case <-time.After(2 * time.Second):
t.Fatal("SetEnabled(false) timed out waiting for update loop shutdown")
}
}