- TestCalculateNextRetry: allow small negative delay for attempt 0 (immediate retry causes timing-based test flakiness) - TestPriorityConstants: change assertions from int32 to int (constants are untyped int, not int32) - TestOfflineDetector_*: Move integration tests to cmd/server/tests/ These tests were failing due to type mismatches and timing issues. All are now fixed and passing.
60 lines
1.8 KiB
Go
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, int(1), PriorityUserInitiated)
|
|
assert.Equal(t, int(2), PriorityBookCompletion)
|
|
assert.Equal(t, int(3), PriorityCriticalNote)
|
|
assert.Equal(t, int(5), PriorityPageTurn)
|
|
assert.Equal(t, int(7), PriorityCheckpoint)
|
|
assert.Equal(t, int(10), PriorityBackgroundSync)
|
|
}
|