package main import "testing" // 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() d.rxStats[0].frames.Store(150) d.rxStats[0].bytes.Store(9600) d.reset() v := d.displayView() if v.rxFrames != 0 { t.Errorf("rxFrames = %d, want 0", v.rxFrames) } if v.rxBytes != 0 { t.Errorf("rxBytes = %d, want 0", v.rxBytes) } // 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) } }