package ingest
import (
"errors"
"testing"
"time"
)
// A write op's TrySync never waits on a round that holds the pipeline:
// it answers ErrRoundBusy at once (#481), and runs a round when none is.
func TestTrySyncAnswersBusyWhileARoundHoldsThePipeline(t *testing.T) {
pipe, _, _ := testPipeline(t)
pipe.mu.Lock()
start := time.Now()
_, err := pipe.TrySync()
took := time.Since(start)
pipe.mu.Unlock()
if !errors.Is(err, ErrRoundBusy) {
t.Errorf("FAIL: TrySync while held = %v, want ErrRoundBusy", err)
}
if took > time.Second {
t.Errorf("FAIL: TrySync waited %v on a held pipeline", took)
}
if _, err := pipe.TrySync(); err != nil {
t.Errorf("FAIL: TrySync on a free pipeline = %v", err)
}
if !t.Failed() {
t.Log("ok")
}
}