package main import ( "context" "errors" "tera-clone/services/tera-api/internal/serial" "testing" ) func TestStartupSerialRetriesOnlyBusy(t *testing.T) { calls := 0 err := retryStartupSerial(context.Background(), func() error { calls++ if calls == 1 { return serial.ErrStreamLeaseBusy } return nil }) if err != nil || calls != 2 { t.Fatalf("calls=%d err=%v", calls, err) } calls = 0 failure := errors.New("invalid config") err = retryStartupSerial(context.Background(), func() error { calls++; return failure }) if !errors.Is(err, failure) || calls != 1 { t.Fatal("non-busy failure retried") } ctx, cancel := context.WithCancel(context.Background()) err = retryStartupSerial(ctx, func() error { cancel(); return serial.ErrStreamLeaseBusy }) if !errors.Is(err, context.Canceled) { t.Fatal(err) } }