mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-22 02:27:57 +00:00
test✅: dial the stalling connection after the signal, not at start-up
net/http stops counting a StateNew connection against Shutdown once it is more than five seconds old. The connection was opened when the child started and the parent then waited for readiness before signalling, so on a slow run the connection could age past that mark and Shutdown would succeed - and the test would fail on its own "this proves nothing" guard rather than on the behaviour it is there to pin. Opening it immediately before the shutdown keeps the timeout deterministic. Claude-Session: https://claude.ai/code/session_01HPTAw8b8tAdFNFn8rKdPYx
This commit is contained in:
+10
-9
@@ -44,15 +44,6 @@ func TestSignalChild(t *testing.T) {
|
||||
srv := &http.Server{Handler: http.NewServeMux()}
|
||||
go func() { _ = srv.Serve(ln) }()
|
||||
|
||||
if os.Getenv(childHangConn) == "1" {
|
||||
c, err := net.Dial("tcp", ln.Addr().String())
|
||||
if err != nil {
|
||||
fmt.Println("dial:", err)
|
||||
os.Exit(5)
|
||||
}
|
||||
defer func() { _ = c.Close() }()
|
||||
}
|
||||
|
||||
// Arm before announcing readiness. Doing it the other way round leaves a
|
||||
// window in which the parent's signal reaches the default handler and
|
||||
// kills the child before any of this runs - which is exactly the failure
|
||||
@@ -77,6 +68,16 @@ func TestSignalChild(t *testing.T) {
|
||||
|
||||
timeout := shutdownTimeout
|
||||
if os.Getenv(childHangConn) == "1" {
|
||||
// Dialled here, not at start-up. net/http stops counting a StateNew
|
||||
// connection against Shutdown once it is more than five seconds old,
|
||||
// so a connection opened before the wait would age out on a slow CI
|
||||
// run and Shutdown would succeed - leaving the test asserting nothing.
|
||||
c, err := net.Dial("tcp", ln.Addr().String())
|
||||
if err != nil {
|
||||
fmt.Println("dial:", err)
|
||||
os.Exit(5)
|
||||
}
|
||||
defer func() { _ = c.Close() }()
|
||||
|
||||
// A connection that has sent nothing keeps Shutdown busy: net/http
|
||||
// only treats a StateNew connection as idle once it is more than five
|
||||
|
||||
Reference in New Issue
Block a user