Files
graphql-monitoring-proxy/backend_health_deadline_test.go
T
lukaszraczylo 3e187790f2 fix(health): stop startup wait at its timeout
The startup probe slept a full backoff step even when the deadline was closer. A 31 second timeout ended after about 41 seconds. The probe now sleeps no longer than the time left.
2026-11-03 00:23:56 +00:00

33 lines
922 B
Go

package main
import (
"net"
"testing"
"time"
libpack_logger "github.com/lukaszraczylo/graphql-monitoring-proxy/logging"
"github.com/valyala/fasthttp"
)
// Pins theorems/Theorems/ReadyBackoff.lean: the startup wait never sleeps past its timeout.
func TestWaitForBackendReady_HonoursTimeout(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
addr := ln.Addr().String()
_ = ln.Close() // closed port: every probe is refused immediately
bhm := NewBackendHealthManager(&fasthttp.Client{}, "http://"+addr, "", libpack_logger.New())
defer bhm.cancel()
const timeout = 3 * time.Second
start := time.Now()
if err := bhm.WaitForBackendReady(timeout); err == nil {
t.Fatal("want error for unreachable backend")
}
if elapsed := time.Since(start); elapsed > timeout+500*time.Millisecond {
t.Fatalf("waited %v, want <= %v", elapsed, timeout+500*time.Millisecond)
}
}