playlist timer pause/resume without affecting active feeds
This commit is contained in:
@@ -255,6 +255,113 @@ func TestPlaylistControllerCancellationStopsTimer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaylistControllerPauseAndResumeTimer(t *testing.T) {
|
||||
controller, commands, readiness, sessions, timers, now, cancel, result :=
|
||||
startTimedPlaylistController(t, timedPlaylist(false))
|
||||
defer cancel()
|
||||
|
||||
commands <- PlaylistCommand{Kind: PlaylistNext}
|
||||
_ = receivePlaylistSession(t, sessions)
|
||||
readiness <- PlaylistReadiness{Revision: 1}
|
||||
oldTimer := receiveFakePlaylistTimer(t, timers)
|
||||
waitForPlaylistSnapshot(t, controller, func(snapshot PlaylistSnapshot) bool {
|
||||
return snapshot.Timing.Started
|
||||
})
|
||||
|
||||
commands <- PlaylistCommand{Kind: PlaylistPause}
|
||||
paused := waitForPlaylistSnapshot(t, controller, func(snapshot PlaylistSnapshot) bool {
|
||||
return snapshot.Timing.Paused
|
||||
})
|
||||
if paused.Revision != 1 || paused.Timing.Started {
|
||||
t.Fatalf("paused snapshot = %#v", paused)
|
||||
}
|
||||
if !oldTimer.isStopped() {
|
||||
t.Fatal("Pause did not stop active timer")
|
||||
}
|
||||
oldTimer.fire(now.Add(10 * time.Second))
|
||||
select {
|
||||
case command := <-sessions:
|
||||
t.Fatalf("paused stale timer sent session command: %#v", command)
|
||||
case <-time.After(20 * time.Millisecond):
|
||||
}
|
||||
|
||||
commands <- PlaylistCommand{Kind: PlaylistResume}
|
||||
_ = receiveFakePlaylistTimer(t, timers)
|
||||
resumed := waitForPlaylistSnapshot(t, controller, func(snapshot PlaylistSnapshot) bool {
|
||||
return snapshot.Timing.Started && !snapshot.Timing.Paused
|
||||
})
|
||||
if resumed.Revision != 1 {
|
||||
t.Fatalf("resume changed revision: %#v", resumed)
|
||||
}
|
||||
select {
|
||||
case command := <-sessions:
|
||||
t.Fatalf("pause/resume sent session command: %#v", command)
|
||||
default:
|
||||
}
|
||||
|
||||
close(commands)
|
||||
if err := waitForPlaylistResult(t, result); err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaylistControllerManualSelectionClearsPause(t *testing.T) {
|
||||
controller, commands, _, sessions, _, _, cancel, result :=
|
||||
startTimedPlaylistController(t, timedPlaylist(false))
|
||||
defer cancel()
|
||||
|
||||
commands <- PlaylistCommand{Kind: PlaylistNext}
|
||||
_ = receivePlaylistSession(t, sessions)
|
||||
commands <- PlaylistCommand{Kind: PlaylistPause}
|
||||
waitForPlaylistSnapshot(t, controller, func(snapshot PlaylistSnapshot) bool {
|
||||
return snapshot.Timing.Paused
|
||||
})
|
||||
|
||||
commands <- PlaylistCommand{Kind: PlaylistNext}
|
||||
_ = receivePlaylistSession(t, sessions)
|
||||
next := waitForPlaylistSnapshot(t, controller, func(snapshot PlaylistSnapshot) bool {
|
||||
return snapshot.Revision == 2
|
||||
})
|
||||
if next.Timing.Paused || next.State.CurrentIndex != 1 {
|
||||
t.Fatalf("new selection retained pause: %#v", next)
|
||||
}
|
||||
|
||||
close(commands)
|
||||
if err := waitForPlaylistResult(t, result); err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaylistControllerRecordsQueuedReadinessWhilePaused(t *testing.T) {
|
||||
controller, commands, readiness, sessions, timers, _, cancel, result :=
|
||||
startTimedPlaylistController(t, timedPlaylist(false))
|
||||
defer cancel()
|
||||
|
||||
commands <- PlaylistCommand{Kind: PlaylistNext}
|
||||
_ = receivePlaylistSession(t, sessions)
|
||||
commands <- PlaylistCommand{Kind: PlaylistPause}
|
||||
waitForPlaylistSnapshot(t, controller, func(snapshot PlaylistSnapshot) bool {
|
||||
return snapshot.Timing.Paused
|
||||
})
|
||||
|
||||
readiness <- PlaylistReadiness{Revision: 1}
|
||||
waitForPlaylistSnapshot(t, controller, func(snapshot PlaylistSnapshot) bool {
|
||||
return snapshot.Timing.Paused && snapshot.Timing.Ready
|
||||
})
|
||||
assertNoPlaylistTimer(t, timers)
|
||||
|
||||
commands <- PlaylistCommand{Kind: PlaylistResume}
|
||||
_ = receiveFakePlaylistTimer(t, timers)
|
||||
waitForPlaylistSnapshot(t, controller, func(snapshot PlaylistSnapshot) bool {
|
||||
return snapshot.Timing.Started && !snapshot.Timing.Paused
|
||||
})
|
||||
|
||||
close(commands)
|
||||
if err := waitForPlaylistResult(t, result); err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func startTimedPlaylistController(
|
||||
t *testing.T,
|
||||
playlist Playlist,
|
||||
|
||||
Reference in New Issue
Block a user