0.2.68
This commit is contained in:
@@ -85,6 +85,26 @@ type fakeBehaviour struct{ stops []StopEvent }
|
||||
|
||||
func (b fakeBehaviour) Stops(context.Context, string) ([]StopEvent, error) { return b.stops, nil }
|
||||
|
||||
type fixedCandidates []Candidate
|
||||
|
||||
func (f fixedCandidates) Candidates(context.Context) ([]Candidate, error) { return f, nil }
|
||||
|
||||
type fakeHistory struct {
|
||||
recent map[string]time.Time
|
||||
attempts []ScanAttempt
|
||||
}
|
||||
|
||||
func (h *fakeHistory) SaveScanAttempt(_ context.Context, attempt ScanAttempt) error {
|
||||
h.attempts = append(h.attempts, attempt)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *fakeHistory) RecentScanTimes(
|
||||
_ context.Context, _ []string, _ time.Time,
|
||||
) (map[string]time.Time, error) {
|
||||
return h.recent, nil
|
||||
}
|
||||
|
||||
func quietLog() *slog.Logger {
|
||||
return slog.New(slog.NewTextHandler(io.Discard, &slog.HandlerOptions{Level: slog.LevelError}))
|
||||
}
|
||||
@@ -356,3 +376,42 @@ func TestSustainedPlaybackIsQueuedAtLivePriority(t *testing.T) {
|
||||
t.Fatalf("candidate = %+v, want live playback at priority %d", pending[0], PriorityLive)
|
||||
}
|
||||
}
|
||||
|
||||
// An inconclusive scan used to be forgotten, so the ten-minute refresh selected the same
|
||||
// episode for ever. History now makes that episode ineligible until its cooldown expires.
|
||||
func TestRefreshDefersRecentlyScannedCandidate(t *testing.T) {
|
||||
media := testMedia()
|
||||
history := &fakeHistory{recent: map[string]time.Time{media.Version.ItemID: time.Now()}}
|
||||
service := New(Deps{
|
||||
Repository: newFakeRepo(), History: history,
|
||||
Resolver: &fakeResolver{media: map[string]ResolvedMedia{media.Version.ItemID: media}},
|
||||
Source: fixedCandidates{{ItemID: media.Version.ItemID, Priority: PriorityNext}},
|
||||
Log: quietLog(), Config: DefaultConfig(),
|
||||
})
|
||||
|
||||
detail, err := service.Refresh(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if service.QueueDepth() != 0 {
|
||||
t.Fatal("a recently scanned episode returned to the queue")
|
||||
}
|
||||
if detail != "1 candidate cooling down, 0 already known" {
|
||||
t.Fatalf("refresh detail = %q", detail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanAttemptHistoryDescribesNoMatch(t *testing.T) {
|
||||
history := &fakeHistory{}
|
||||
service := New(Deps{
|
||||
Repository: newFakeRepo(), History: history,
|
||||
Resolver: &fakeResolver{media: map[string]ResolvedMedia{}},
|
||||
Log: quietLog(), Config: DefaultConfig(),
|
||||
})
|
||||
candidate := Candidate{ItemID: "episode-7", Reason: ReasonNext, Priority: PriorityNext}
|
||||
service.recordAttempt(context.Background(), candidate, Detection{FramesSampled: 42}, false, nil, time.Now().Add(-time.Second))
|
||||
|
||||
if len(history.attempts) != 1 || history.attempts[0].Outcome != "no_match" || history.attempts[0].Frames != 42 {
|
||||
t.Fatalf("history = %+v", history.attempts)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user