beacon_counter_2221_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package httpapi
  2. import "testing"
  3. // #2221: los contadores del beacon son de 32 bits y `deriveFps` lee la
  4. // envoltura como un reset, así que el ingest tiene que desenrollarlos.
  5. func TestUnwrapBeaconCounterWrapsAt2To32(t *testing.T) {
  6. v1, st := unwrapBeaconCounter(beaconCounter{}, false, 4_294_967_290, 1000)
  7. if v1 != 4_294_967_290 {
  8. t.Fatalf("primer valor: %d", v1)
  9. }
  10. v2, _ := unwrapBeaconCounter(st, true, 5, 1001)
  11. if got := v2 - v1; got != 11 {
  12. t.Fatalf("delta tras la envoltura: %d, esperaba 11", got)
  13. }
  14. }
  15. // Un reinicio del equipo baja el uptime y el contador: no es una envoltura y
  16. // no puede producir una tasa de 2^32 tramas.
  17. func TestUnwrapBeaconCounterRebootIsNotAWrap(t *testing.T) {
  18. _, st := unwrapBeaconCounter(beaconCounter{}, false, 4_294_967_290, 1000)
  19. v2, _ := unwrapBeaconCounter(st, true, 5, 3)
  20. v3, _ := unwrapBeaconCounter(beaconCounter{raw: 5, up: 3}, true, 7, 5)
  21. if v3 <= v2 {
  22. t.Fatalf("el contador debe seguir: v2=%d v3=%d", v2, v3)
  23. }
  24. if v3-v2 != 2 {
  25. t.Fatalf("delta tras reinicio: %d, esperaba 2", v3-v2)
  26. }
  27. }
  28. // Un reinicio del proceso sin reinicio del equipo (mismo uptime, contador a
  29. // cero) tampoco es una envoltura: se reinicia la base, sin pico.
  30. func TestUnwrapBeaconCounterProcessResetIsNotAWrap(t *testing.T) {
  31. _, st := unwrapBeaconCounter(beaconCounter{}, false, 900_000_000, 1000)
  32. v2, _ := unwrapBeaconCounter(st, true, 12, 1001)
  33. if v2 != 12 {
  34. t.Fatalf("reset sin reinicio: %d, esperaba 12", v2)
  35. }
  36. }