37 lines
937 B
Go
37 lines
937 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestAdaptiveSizerRecoversFromMinimum(t *testing.T) {
|
|
opts := chunkClientOptions{
|
|
startSize: 64,
|
|
minSize: 32,
|
|
maxSize: 1024,
|
|
adaptive: true,
|
|
adaptSuccesses: 2,
|
|
}
|
|
s := newAdaptiveSizer("test", opts)
|
|
_, next := s.Failure(64)
|
|
if next != 32 {
|
|
t.Fatalf("failure should reduce 64 -> 32, got %d", next)
|
|
}
|
|
|
|
// When good=32 and bad=64 are adjacent at the controller's probing
|
|
// granularity, it deliberately waits 8x longer before testing upward.
|
|
for i := 0; i < 16; i++ {
|
|
s.Success(32)
|
|
}
|
|
if got := s.Current(); got <= 32 {
|
|
t.Fatalf("adaptive controller remained stuck at minimum: %d", got)
|
|
}
|
|
}
|
|
|
|
func TestWireTokenAllowsEmptyToken(t *testing.T) {
|
|
if got := wireToken(""); got != "-" {
|
|
t.Fatalf("empty token wire representation = %q, want '-'", got)
|
|
}
|
|
if got := wireToken("secret"); got != "secret" {
|
|
t.Fatalf("non-empty token changed: %q", got)
|
|
}
|
|
}
|