filterrange_test.go raw
1 package neutrino
2
3 import "testing"
4
5 // TestFilterRangeNeverGoesBackwards: a limit that is already met must end the loop, not produce a
6 // request whose stop is below its start. A node treats that as a bad request and closes the
7 // connection, which looks like a transport failure at the next write.
8 func TestFilterRangeNeverGoesBackwards(t *testing.T) {
9 const tip = 1000
10
11 cases := []struct {
12 start, batch, max, count int
13 ok bool
14 end uint32
15 }{
16 {start: 0, batch: 500, max: 0, count: 0, ok: true, end: 499},
17 {start: 900, batch: 500, max: 0, count: 0, ok: true, end: tip},
18 {start: 0, batch: 500, max: 20, count: 0, ok: true, end: 19},
19 {start: 0, batch: 500, max: 20, count: 20, ok: false},
20 {start: 100, batch: 500, max: 10, count: 10, ok: false},
21 {start: 100, batch: 1, max: 0, count: 0, ok: true, end: 100},
22 }
23
24 for _, c := range cases {
25 end, ok := filterRange(uint32(c.start), tip, c.batch, c.max, c.count)
26
27 if ok != c.ok || (ok && end != c.end) {
28 t.Fatalf("start=%d batch=%d max=%d count=%d: got (%d,%v), want (%d,%v)",
29 c.start, c.batch, c.max, c.count, end, ok, c.end, c.ok)
30 }
31 }
32 }
33