package main

import "testing"

func TestAdaptiveSizerRecoversFromMinimum(t *testing.T) {
	opts := chunkClientOptions{
		startSize:      64,
		minSize:        32,
		maxSize:        1024,
		adaptive:       true,
		adaptSuccesses: 2,
	}
	s := newAdaptiveSizer("test", 64, opts)
	_, next := s.Failure(64)
	if next != 32 {
		t.Fatalf("failure should reduce 64 -> 32, got %d", next)
	}
	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 TestReconnectZeroMeansPersistent(t *testing.T) {
	lane := newRequestLane("127.0.0.1:1", 0, 0, 0)
	if lane.reconnectEvery != 0 {
		t.Fatalf("reconnectEvery=%d, want 0", lane.reconnectEvery)
	}
}
