mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-24 04:33:17 +00:00
test(telemetry): run background health checks with a test delay
Retain the two-minute production constant and extract the same background runner with an explicit test-only delay argument. Correct the startup non-blocking regression after exact-source proof found its invalid constant assignment. Contract-Neutral: Extract the unchanged telemetry background runner for deterministic testing; production scheduling, payload and privacy contracts are unchanged. Change-source: pulse-maintainer
This commit is contained in:
@@ -221,18 +221,16 @@ func TestServiceHealthFailureCategoriesSerializeAndPersist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTelemetryStartDoesNotWaitForServiceHealth(t *testing.T) {
|
||||
originalDelay := startupDelay
|
||||
startupDelay = 0
|
||||
defer func() { startupDelay = originalDelay }()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
entered, release, started := make(chan struct{}), make(chan struct{}), make(chan struct{})
|
||||
dir := t.TempDir()
|
||||
t.Cleanup(func() { close(release); cancel(); Stop() })
|
||||
go func() {
|
||||
Start(ctx, Config{Enabled: true, Version: "6.4.6", DataDir: t.TempDir(), GetServiceHealth: func() ServiceHealthObservation {
|
||||
startWithDelay(ctx, Config{Enabled: true, Version: "6.4.6", DataDir: dir, GetServiceHealth: func() ServiceHealthObservation {
|
||||
close(entered)
|
||||
<-release
|
||||
return ServiceHealthObservation{Observed: true, Healthy: true}
|
||||
}})
|
||||
}}, 0)
|
||||
close(started)
|
||||
}()
|
||||
select {
|
||||
|
||||
@@ -1125,6 +1125,12 @@ var (
|
||||
//
|
||||
// This is a no-op when outbound usage telemetry is disabled.
|
||||
func Start(ctx context.Context, cfg Config) {
|
||||
startWithDelay(ctx, cfg, startupDelay)
|
||||
}
|
||||
|
||||
// Keep the production settling delay constant while allowing deterministic
|
||||
// tests to exercise the same background runner without a two-minute sleep.
|
||||
func startWithDelay(ctx context.Context, cfg Config, initialDelay time.Duration) {
|
||||
if !cfg.Enabled {
|
||||
log.Info().Msg("Outbound usage telemetry is disabled (enable via PULSE_TELEMETRY=true or Settings → System)")
|
||||
return
|
||||
@@ -1154,7 +1160,7 @@ func Start(ctx context.Context, cfg Config) {
|
||||
defer r.wg.Done()
|
||||
|
||||
// Wait for the monitor to connect and populate state before the first ping.
|
||||
startTimer := time.NewTimer(startupDelay)
|
||||
startTimer := time.NewTimer(initialDelay)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
startTimer.Stop()
|
||||
|
||||
Reference in New Issue
Block a user