package runner

import (
	"testing"
	"time"
)

func TestPassiveRouteObserverRecordsOnlyTransportPhaseFacts(t *testing.T) {
	observer := &passiveRouteObserver{}
	startedAt := time.Now()
	observer.record(true, 10*time.Millisecond, 1024, startedAt, startedAt.Add(time.Millisecond))
	observer.record(false, 20*time.Millisecond, 2048, startedAt, startedAt.Add(2*time.Millisecond))
	observer.record(true, 30*time.Millisecond, 0, startedAt, time.Time{})

	observation := observer.snapshot("pool-a", "route-a")
	if observation.SampleCount != 3 || observation.SuccessCount != 2 {
		t.Fatalf("observation=%+v", observation)
	}
	if observation.ConnectTLSP95 != 30*time.Millisecond {
		t.Fatalf("connect/TLS p95=%s", observation.ConnectTLSP95)
	}
	if observation.UploadBytesPerSecond < 1_024_000-1 || observation.UploadBytesPerSecond > 1_024_000+1 {
		t.Fatalf("upload rate=%f", observation.UploadBytesPerSecond)
	}
}
