Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

33 lines
1.1 KiB
Go

package daemon
import "testing"
// TestDeadPeerSweepRemovesDeadSession proves the registry reaps sessions whose
// originating client process has died (by handshake PID) while leaving live
// sessions and PID-less (detached/HTTP) sessions untouched.
func TestDeadPeerSweepRemovesDeadSession(t *testing.T) {
r := NewSessionRegistry()
r.RegisterDetached("live", Handshake{PID: 111, Mode: ModeMCP})
r.RegisterDetached("dead", Handshake{PID: 222, Mode: ModeMCP})
r.RegisterDetached("nopid", Handshake{PID: 0, Mode: ModeMCP})
// Only PID 111 is alive.
removed := r.SweepDead(func(pid int) bool { return pid == 111 })
if len(removed) != 1 || removed[0].ID != "dead" {
t.Fatalf("SweepDead removed = %+v, want exactly [dead]", removed)
}
if r.GetByID("dead") != nil {
t.Error("a dead-PID session must be removed from the registry")
}
if r.GetByID("live") == nil {
t.Error("a live-PID session must remain")
}
if r.GetByID("nopid") == nil {
t.Error("a session with no recorded PID (0) must NOT be swept — liveness is unknown")
}
if r.Count() != 2 {
t.Errorf("Count() = %d, want 2 after the sweep", r.Count())
}
}