Files
bookhoard/internal/sync/queue_test.go
T
john-okeefe e389df92c3 refactor: remove unnecessary type conversions and handle ignored errors across codebase
Remove redundant type conversions that Go 1.26 makes unnecessary or that
were already no-ops:

- uuid.UUID(x.Bytes) → x.Bytes (uuid.UUID is [16]byte, same as pgtype UUID Bytes)
- pgtype.UUID{Bytes: [16]byte(u), Valid: true} → pgtype.UUID{Bytes: u, Valid: true}
- (*time.Time)(&x.Time) → &x.Time
- json.RawMessage(x) → x where x is already []byte
- []byte(stringVal) → stringVal where []byte is expected
- int()/int64()/byte() casts on values already of the target type
- Decompressor(fn) → fn (type is identical)

Handle previously ignored error returns:

- collections.go: check json.Unmarshal error in GetCollection
- conversion_service.go: check fileSize.Scan() error
- app_test.go: check app.Shutdown() error in benchmark
2026-04-21 21:15:59 -04:00

60 lines
1.8 KiB
Go

package sync
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCalculateNextRetry(t *testing.T) {
processor := NewSyncQueueProcessor(nil)
tests := []struct {
name string
attempts int32
minDelay time.Duration
maxDelay time.Duration
}{
{"Attempt 0", 0, -100 * time.Millisecond, 1 * time.Second},
{"Attempt 1", 1, 59 * time.Second, 61 * time.Second},
{"Attempt 2", 2, 4*time.Minute + 59*time.Second, 5*time.Minute + 1*time.Second},
{"Attempt 3", 3, 14*time.Minute + 59*time.Second, 15*time.Minute + 1*time.Second},
{"Attempt 4", 4, 59*time.Minute + 59*time.Second, 60*time.Minute + 1*time.Second},
{"Attempt 5", 5, 23*time.Hour + 59*time.Minute, 24*time.Hour + 1*time.Minute},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
nextRetry := processor.calculateNextRetry(tt.attempts)
delay := nextRetry.Sub(time.Now())
assert.GreaterOrEqual(t, delay, tt.minDelay, "delay should be at least minDelay")
assert.LessOrEqual(t, delay, tt.maxDelay, "delay should be at most maxDelay")
})
}
}
func TestSyncTypeConstants(t *testing.T) {
assert.Equal(t, "progress", SyncTypeProgress)
assert.Equal(t, "note", SyncTypeNote)
assert.Equal(t, "highlight", SyncTypeHighlight)
assert.Equal(t, "bookmark", SyncTypeBookmark)
}
func TestSyncStatusConstants(t *testing.T) {
assert.Equal(t, "pending", SyncStatusPending)
assert.Equal(t, "processing", SyncStatusProcessing)
assert.Equal(t, "completed", SyncStatusCompleted)
assert.Equal(t, "failed", SyncStatusFailed)
}
func TestPriorityConstants(t *testing.T) {
assert.Equal(t, 1, PriorityUserInitiated)
assert.Equal(t, 2, PriorityBookCompletion)
assert.Equal(t, 3, PriorityCriticalNote)
assert.Equal(t, 5, PriorityPageTurn)
assert.Equal(t, 7, PriorityCheckpoint)
assert.Equal(t, 10, PriorityBackgroundSync)
}