generation-aware playlist readiness

This commit is contained in:
Dmitry Sergeev
2026-09-01 20:05:00 +03:00
parent b160e3aba2
commit 532e03ffca
4 changed files with 349 additions and 0 deletions
+66
View File
@@ -153,3 +153,69 @@ func TestStatusStoreKeepsEqualGenerationUnitsIndependent(t *testing.T) {
t.Fatalf("audio Snapshot() = %#v, %t", got, ok)
}
}
func TestStatusStoreSnapshotAll(t *testing.T) {
store := NewStatusStore()
wantVideo := Status{Unit: UnitVideo, State: StatePlaying, Generation: 5}
wantAudio := Status{Unit: UnitAudio, State: StateReconnecting, Generation: 5}
store.Observe(wantVideo)
store.Observe(wantAudio)
got := store.SnapshotAll()
if got.Generation != 5 {
t.Fatalf("SnapshotAll() generation = %d, want 5", got.Generation)
}
if !got.HasVideo || got.Video != wantVideo {
t.Fatalf("SnapshotAll() video = %#v, %v; want %#v, true", got.Video, got.HasVideo, wantVideo)
}
if !got.HasAudio || got.Audio != wantAudio {
t.Fatalf("SnapshotAll() audio = %#v, %v; want %#v, true", got.Audio, got.HasAudio, wantAudio)
}
if got.HasSync {
t.Fatalf("SnapshotAll() HasSync = true, want false")
}
}
func TestStatusStoreSnapshotAllClearsOldGenerationUnits(t *testing.T) {
store := NewStatusStore()
store.Observe(Status{Unit: UnitVideo, State: StatePlaying, Generation: 2})
store.Observe(Status{Unit: UnitAudio, State: StatePlaying, Generation: 2})
wantSync := Status{Unit: UnitSync, State: StateConnecting, Generation: 3}
store.Observe(wantSync)
got := store.SnapshotAll()
if got.Generation != 3 {
t.Fatalf("SnapshotAll() generation = %d, want 3", got.Generation)
}
if got.HasVideo || got.HasAudio {
t.Fatalf("SnapshotAll() retained old units: %#v", got)
}
if !got.HasSync || got.Sync != wantSync {
t.Fatalf("SnapshotAll() sync = %#v, %v; want %#v, true", got.Sync, got.HasSync, wantSync)
}
}
func TestStatusStoreSnapshotAllConcurrentObserve(t *testing.T) {
store := NewStatusStore()
done := make(chan struct{})
go func() {
defer close(done)
for generation := uint64(1); generation <= 1000; generation++ {
store.Observe(Status{
Unit: Unit(generation % 3),
State: StatePlaying,
Generation: generation,
})
}
}()
for {
select {
case <-done:
_ = store.SnapshotAll()
return
default:
_ = store.SnapshotAll()
}
}
}