Files
cabletest/main_test.go
T

39 lines
956 B
Go

package main
import (
"testing"
"time"
)
// A reset re-bases from a fresh capture while the ring still holds buckets from
// just before it, so the newest bucket must not be left behind the new origin.
func TestResetDoesNotUnderflowTotals(t *testing.T) {
d := &direction{
win: newRateWindow(8),
cable: newCableStats(),
rxStats: []*rxStats{{}},
}
d.rxStats[0].frames.Store(100)
d.rxStats[0].bytes.Store(6400)
d.sample(time.Now())
d.rxStats[0].frames.Store(150)
d.rxStats[0].bytes.Store(9600)
d.reset()
v := d.displayView(time.Now())
if v.rxFrames != 0 {
t.Errorf("rxFrames = %d, want 0", v.rxFrames)
}
if v.rxGot != 0 {
t.Errorf("rxGot = %d, want 0", v.rxGot)
}
// The rolling window and the rates are about now rather than since the
// reset, so the buckets from before it have to survive.
if got := d.win.count(); got < 2 {
t.Errorf("ring holds %d buckets after reset, want the pre-reset history kept", got)
}
}