move MXL retry policy to adapter

This commit is contained in:
Dmitry Sergeev
2026-08-27 09:12:17 +03:00
parent e19f02edbf
commit 4f6ee895e7
2 changed files with 5 additions and 4 deletions
-24
View File
@@ -1,24 +0,0 @@
package playback
import (
"context"
"errors"
"mxl-player/internal/source"
)
func shouldRetrySourceError(err error) bool {
if errors.Is(err, context.Canceled) {
return false
}
switch source.KindOf(err) {
case source.ErrorKindInvalidConfig:
return false
case source.ErrorKindTemporary,
source.ErrorKindUnavailable,
source.ErrorKindUnknown:
return true
default:
return true
}
}
-74
View File
@@ -1,74 +0,0 @@
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)
}
})
}
}