You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
834 B

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)
}
}