define source retry decisions

This commit is contained in:
Dmitry Sergeev
2026-08-27 08:58:16 +03:00
parent 89a0522e20
commit 5d3b465e1e
2 changed files with 98 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
package playback
import (
"context"
"errors"
"fmt"
"testing"
"mxl-player/internal/source"
)
func TestShouldRetrySourceError(t *testing.T) {
baseErr := errors.New("source failed")
classified := func(kind source.ErrorKind) error {
return &source.SourceError{
Op: "read media",
Kind: kind,
Err: baseErr,
}
}
tests := []struct {
name string
err error
want bool
}{
{
name: "temporary source error is retryable",
err: classified(source.ErrorKindTemporary),
want: true,
},
{
name: "unavailable source is retryable",
err: classified(source.ErrorKindUnavailable),
want: true,
},
{
name: "invalid configuration is not retryable",
err: classified(source.ErrorKindInvalidConfig),
want: false,
},
{
name: "ordinary unknown error is retryable",
err: baseErr,
want: true,
},
{
name: "wrapped invalid configuration is not retryable",
err: fmt.Errorf(
"worker failed: %w",
classified(source.ErrorKindInvalidConfig),
),
want: false,
},
{
name: "context cancellation is not retryable",
err: context.Canceled,
want: false,
},
{
name: "wrapped context cancellation is not retryable",
err: fmt.Errorf("worker stopped: %w", context.Canceled),
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := shouldRetrySourceError(tt.err); got != tt.want {
t.Errorf("shouldRetrySourceError() = %t, want %t", got, tt.want)
}
})
}
}