Cover the loss window, rate window, error taxonomy and formatters with tests
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func newWindow() *lossWindow {
|
||||
w := newLossWindows(1)
|
||||
return &w[0]
|
||||
}
|
||||
|
||||
func TestLossWindowContiguousLosesNothing(t *testing.T) {
|
||||
w := newWindow()
|
||||
for seq := uint64(0); seq < lossSlots+1000; seq++ {
|
||||
w.observe(seq)
|
||||
}
|
||||
if got := w.lost.Load(); got != 0 {
|
||||
t.Errorf("lost = %d, want 0", got)
|
||||
}
|
||||
if got := w.late.Load(); got != 0 {
|
||||
t.Errorf("late = %d, want 0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLossWindowCountsGapOnceEvicted(t *testing.T) {
|
||||
w := newWindow()
|
||||
for seq := uint64(0); seq < lossSlots+1000; seq++ {
|
||||
if seq == 100 {
|
||||
continue
|
||||
}
|
||||
w.observe(seq)
|
||||
}
|
||||
if got := w.lost.Load(); got != 1 {
|
||||
t.Errorf("lost = %d, want 1", got)
|
||||
}
|
||||
}
|
||||
|
||||
// Arriving out of order inside the window is not loss: a sequence is only
|
||||
// judged once it falls out the far end.
|
||||
func TestLossWindowOutOfOrderIsNotLoss(t *testing.T) {
|
||||
w := newWindow()
|
||||
for seq := uint64(99); ; seq-- {
|
||||
w.observe(seq)
|
||||
if seq == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
for seq := uint64(100); seq < lossSlots+1000; seq++ {
|
||||
w.observe(seq)
|
||||
}
|
||||
if got := w.lost.Load(); got != 0 {
|
||||
t.Errorf("lost = %d, want 0", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The other branch of evict: a jump past a whole window writes off everything
|
||||
// the window held plus the sequences that never landed in it at all.
|
||||
func TestLossWindowJumpBeyondWindow(t *testing.T) {
|
||||
w := newWindow()
|
||||
w.observe(0)
|
||||
w.observe(200000)
|
||||
|
||||
// Everything below the new base except the one sequence that was seen.
|
||||
want := uint64(200000 - lossSlots + 1 - 1)
|
||||
if got := w.lost.Load(); got != want {
|
||||
t.Errorf("lost = %d, want %d", got, want)
|
||||
}
|
||||
if got := w.late.Load(); got != 0 {
|
||||
t.Errorf("late = %d, want 0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLossWindowBelowBaseIsLate(t *testing.T) {
|
||||
w := newWindow()
|
||||
w.observe(100000)
|
||||
w.observe(1000)
|
||||
if got := w.late.Load(); got != 1 {
|
||||
t.Errorf("late = %d, want 1", got)
|
||||
}
|
||||
if got := w.lost.Load(); got != 0 {
|
||||
t.Errorf("lost = %d, want 0", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The first sequence seen starts the window half a span below it, so frames
|
||||
// another worker is still holding land inside rather than arriving late.
|
||||
func TestLossWindowStartsHalfAWindowBack(t *testing.T) {
|
||||
w := newWindow()
|
||||
w.observe(100000)
|
||||
if w.base != 100000-lossSlots/2 {
|
||||
t.Errorf("base = %d, want %d", w.base, 100000-lossSlots/2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user