You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
|
2 months ago
|
package serial
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestCRConnectionStatusToleratesTransientMissWithoutInventingCableDown(t *testing.T) {
|
||
|
|
now := time.Date(2026, 9, 14, 1, 0, 0, 0, time.UTC)
|
||
|
|
probe := CRProbeState{Enabled: true, EverUp: true, LastResponseAt: &now}
|
||
|
|
for _, state := range []string{CRProbeStateNoResponse, CRProbeStateBusy, CRProbeStateSuppressed, CRProbeStateError} {
|
||
|
|
probe.State = state
|
||
|
|
for _, age := range []time.Duration{0, 4 * time.Second, CRResponseGracePeriod} {
|
||
|
|
if got := CRConnectionStatus(probe, now.Add(age)); got != "up" {
|
||
|
|
t.Fatalf("transient %s at %s = %s", state, age, got)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if got := CRConnectionStatus(probe, now.Add(CRResponseGracePeriod+time.Millisecond)); got != "unknown" {
|
||
|
|
t.Fatalf("stale %s = %s; no response cannot prove cable down", state, got)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
probe.EverUp = false
|
||
|
|
if CRConnectionStatus(probe, now) != "unknown" {
|
||
|
|
t.Fatal("unconfirmed response promoted")
|
||
|
|
}
|
||
|
|
probe.Up = true
|
||
|
|
if CRConnectionStatus(probe, now) != "up" {
|
||
|
|
t.Fatal("confirmed reply ignored")
|
||
|
|
}
|
||
|
|
probe.Enabled = false
|
||
|
|
if CRConnectionStatus(probe, now) != "unknown" {
|
||
|
|
t.Fatal("disabled probe promoted")
|
||
|
|
}
|
||
|
|
}
|