| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package httpapi
- import "testing"
- // #2221: los contadores del beacon son de 32 bits y `deriveFps` lee la
- // envoltura como un reset, así que el ingest tiene que desenrollarlos.
- func TestUnwrapBeaconCounterWrapsAt2To32(t *testing.T) {
- v1, st := unwrapBeaconCounter(beaconCounter{}, false, 4_294_967_290, 1000)
- if v1 != 4_294_967_290 {
- t.Fatalf("primer valor: %d", v1)
- }
- v2, _ := unwrapBeaconCounter(st, true, 5, 1001)
- if got := v2 - v1; got != 11 {
- t.Fatalf("delta tras la envoltura: %d, esperaba 11", got)
- }
- }
- // Un reinicio del equipo baja el uptime y el contador: no es una envoltura y
- // no puede producir una tasa de 2^32 tramas.
- func TestUnwrapBeaconCounterRebootIsNotAWrap(t *testing.T) {
- _, st := unwrapBeaconCounter(beaconCounter{}, false, 4_294_967_290, 1000)
- v2, _ := unwrapBeaconCounter(st, true, 5, 3)
- v3, _ := unwrapBeaconCounter(beaconCounter{raw: 5, up: 3}, true, 7, 5)
- if v3 <= v2 {
- t.Fatalf("el contador debe seguir: v2=%d v3=%d", v2, v3)
- }
- if v3-v2 != 2 {
- t.Fatalf("delta tras reinicio: %d, esperaba 2", v3-v2)
- }
- }
- // Un reinicio del proceso sin reinicio del equipo (mismo uptime, contador a
- // cero) tampoco es una envoltura: se reinicia la base, sin pico.
- func TestUnwrapBeaconCounterProcessResetIsNotAWrap(t *testing.T) {
- _, st := unwrapBeaconCounter(beaconCounter{}, false, 900_000_000, 1000)
- v2, _ := unwrapBeaconCounter(st, true, 12, 1001)
- if v2 != 12 {
- t.Fatalf("reset sin reinicio: %d, esperaba 12", v2)
- }
- }
|