| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package faults_test
- import (
- "testing"
- "time"
- "hth/internal/faults"
- hthv1 "hth/internal/gen/hth/api/v1"
- )
- func TestAllProtoTypesClassified(t *testing.T) {
- for tpe := hthv1.FaultType_FAULT_TYPE_CONFIG_INVALID; tpe <= hthv1.FaultType_FAULT_TYPE_WATCHDOG_TRIPPED; tpe++ {
- if faults.ClassOf(tpe) == hthv1.FaultClass_FAULT_CLASS_UNSPECIFIED {
- t.Fatalf("unclassified %v", tpe)
- }
- }
- }
- func TestDeviceReportedVsHostInferred(t *testing.T) {
- if faults.HostInferred(hthv1.FaultType_FAULT_TYPE_DEVICE_AXIS_FAULT) {
- t.Fatal("axis fault is device-reported")
- }
- if faults.HostInferred(hthv1.FaultType_FAULT_TYPE_WATCHDOG_TRIPPED) {
- t.Fatal("watchdog tripped is device-reported")
- }
- if !faults.HostInferred(hthv1.FaultType_FAULT_TYPE_CONTROL_LEASE_EXPIRED) {
- t.Fatal("lease expired is host-inferred")
- }
- }
- func TestTransitionUpdateThenClear(t *testing.T) {
- b := faults.NewBook(8)
- now := time.Unix(100, 0)
- f, kind := b.Transition(now, hthv1.FaultType_FAULT_TYPE_SERIAL_DISCONNECTED, "d0", "", "gone", "", nil)
- if kind != "FAULT_RAISED" || f.Count != 1 {
- t.Fatalf("raise %s %+v", kind, f)
- }
- if f.Latched {
- t.Fatal("auto-cleared faults must not be latched without an Acknowledge RPC")
- }
- f, kind = b.Transition(now.Add(time.Second), hthv1.FaultType_FAULT_TYPE_SERIAL_DISCONNECTED, "d0", "", "still gone", "", nil)
- if kind != "FAULT_UPDATED" || f.Count != 2 {
- t.Fatalf("update %s %+v", kind, f)
- }
- cleared := b.Clear(hthv1.FaultType_FAULT_TYPE_SERIAL_DISCONNECTED, "d0", "", now.Add(2*time.Second))
- if cleared == nil || cleared.Active {
- t.Fatal("cleared")
- }
- }
|