playlist retry-exhaustion handling
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
package playback
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIsSessionFailed(t *testing.T) {
|
||||
const generation = 7
|
||||
video := FeedConfig{Domain: "/video", UUID: "video", Active: true}
|
||||
audio := FeedConfig{Domain: "/audio", UUID: "audio", Active: true}
|
||||
failedFeed := func(unit Unit, feed FeedConfig) Status {
|
||||
return Status{
|
||||
Unit: unit, State: StateFailed, Generation: generation, Feed: feed,
|
||||
}
|
||||
}
|
||||
independent := SessionSnapshot{
|
||||
Generation: generation,
|
||||
Plan: SessionPlan{
|
||||
Topology: TopologyIndependent,
|
||||
Video: video,
|
||||
Audio: audio,
|
||||
},
|
||||
}
|
||||
synchronized := SessionSnapshot{
|
||||
Generation: generation,
|
||||
Plan: SessionPlan{
|
||||
Topology: TopologySynchronized,
|
||||
Sync: SyncPairConfig{Video: video, Audio: audio},
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
session SessionSnapshot
|
||||
statuses PlaybackStatusSnapshot
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "video failure in independent pair",
|
||||
session: independent,
|
||||
statuses: PlaybackStatusSnapshot{
|
||||
Generation: generation,
|
||||
Video: failedFeed(UnitVideo, video), HasVideo: true,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "audio failure in independent pair",
|
||||
session: independent,
|
||||
statuses: PlaybackStatusSnapshot{
|
||||
Generation: generation,
|
||||
Audio: failedFeed(UnitAudio, audio), HasAudio: true,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "sync failure",
|
||||
session: synchronized,
|
||||
statuses: PlaybackStatusSnapshot{
|
||||
Generation: generation,
|
||||
Sync: Status{
|
||||
Unit: UnitSync, State: StateFailed, Generation: generation,
|
||||
Pair: SyncPairConfig{Video: video, Audio: audio},
|
||||
},
|
||||
HasSync: true,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "stale snapshot generation",
|
||||
session: independent,
|
||||
statuses: PlaybackStatusSnapshot{
|
||||
Generation: generation - 1,
|
||||
Video: failedFeed(UnitVideo, video), HasVideo: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "wrong source",
|
||||
session: independent,
|
||||
statuses: PlaybackStatusSnapshot{
|
||||
Generation: generation,
|
||||
Video: failedFeed(UnitVideo, FeedConfig{
|
||||
Domain: "/video", UUID: "other", Active: true,
|
||||
}),
|
||||
HasVideo: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "inactive failed unit is ignored",
|
||||
session: SessionSnapshot{
|
||||
Generation: generation,
|
||||
Plan: SessionPlan{
|
||||
Topology: TopologyIndependent,
|
||||
Video: video,
|
||||
Audio: FeedConfig{Domain: audio.Domain, UUID: audio.UUID},
|
||||
},
|
||||
},
|
||||
statuses: PlaybackStatusSnapshot{
|
||||
Generation: generation,
|
||||
Audio: failedFeed(UnitAudio, audio), HasAudio: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reconnecting has not exhausted retries",
|
||||
session: independent,
|
||||
statuses: PlaybackStatusSnapshot{
|
||||
Generation: generation,
|
||||
Video: Status{
|
||||
Unit: UnitVideo, State: StateReconnecting,
|
||||
Generation: generation, Feed: video,
|
||||
},
|
||||
HasVideo: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if got := IsSessionFailed(test.session, test.statuses); got != test.want {
|
||||
t.Fatalf("IsSessionFailed() = %v, want %v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaylistControllerFailurePolicy(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
policy PlaylistFailurePolicy
|
||||
wantAdvance bool
|
||||
}{
|
||||
{name: "wait", policy: PlaylistFailureWait},
|
||||
{name: "next", policy: PlaylistFailureNext, wantAdvance: true},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
playlist := navigationPlaylist(false)
|
||||
playlist.OnFailure = test.policy
|
||||
sessions := make(chan SessionCommand, 4)
|
||||
controller, err := NewPlaylistController(
|
||||
playlist, validPlaylistRetryPolicy(), sessions,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("NewPlaylistController() error = %v", err)
|
||||
}
|
||||
commands := make(chan PlaylistCommand, 2)
|
||||
events := make(chan PlaylistReadiness, 2)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
result := make(chan error, 1)
|
||||
go func() { result <- controller.Run(ctx, commands, events) }()
|
||||
|
||||
commands <- PlaylistCommand{Kind: PlaylistSelect, Index: 0}
|
||||
<-sessions
|
||||
events <- PlaylistEvent{Revision: 1, Kind: PlaylistEventFailed}
|
||||
|
||||
if test.wantAdvance {
|
||||
select {
|
||||
case <-sessions:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("failure did not advance playlist")
|
||||
}
|
||||
snapshot, _ := controller.Snapshot()
|
||||
if snapshot.State.CurrentIndex != 1 || snapshot.Revision != 2 {
|
||||
t.Fatalf("snapshot = %#v, want index 1 revision 2", snapshot)
|
||||
}
|
||||
} else {
|
||||
select {
|
||||
case command := <-sessions:
|
||||
t.Fatalf("unexpected session command: %#v", command)
|
||||
case <-time.After(20 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
|
||||
cancel()
|
||||
if err := <-result; err != context.Canceled {
|
||||
t.Fatalf("Run() error = %v, want context canceled", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user