package httpdl import "testing" // TestBelowSpeed covers the speedGuard decision, including the counter-reset // case (item [1]): d.completed can jump backward when singleOnce rewrites it // with an absolute StoreInt64 and a resumed Range is answered by a 200 that // resets the offset to 0. A backward jump must NOT be read as a slow window, or // a healthy download would be false-aborted. func TestBelowSpeed(t *testing.T) { const limit = 1000 cases := []struct { name string prev, now int64 want bool }{ {"fast", 0, 5000, false}, {"exactly at limit aborts", 1000, 2000, true}, {"just under limit aborts", 1000, 1999, true}, {"just over limit ok", 1000, 2001, false}, {"stalled aborts", 4242, 4242, true}, {"counter reset is not slow", 1_000_000, 0, false}, {"small backward jump is not slow", 5000, 4500, false}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { if got := belowSpeed(c.prev, c.now, limit); got != c.want { t.Errorf("belowSpeed(%d, %d, %d) = %v; want %v", c.prev, c.now, limit, got, c.want) } }) } }