generation-aware playback statuses

This commit is contained in:
Dmitry Sergeev
2026-09-01 18:03:18 +03:00
parent 7a19fe0dad
commit 9bc08109fc
12 changed files with 210 additions and 41 deletions
+47
View File
@@ -106,3 +106,50 @@ func TestStatusStoreConcurrentAccess(t *testing.T) {
}
}
}
func TestStatusStoreNewGenerationClearsPreviousUnits(t *testing.T) {
store := NewStatusStore()
store.Observe(Status{Unit: UnitVideo, State: StatePlaying, Generation: 1})
store.Observe(Status{Unit: UnitAudio, State: StatePlaying, Generation: 1})
want := Status{Unit: UnitSync, State: StateConnecting, Generation: 2}
store.Observe(want)
if _, ok := store.Snapshot(UnitVideo); ok {
t.Fatal("video status survived generation change")
}
if _, ok := store.Snapshot(UnitAudio); ok {
t.Fatal("audio status survived generation change")
}
if got, ok := store.Snapshot(UnitSync); !ok || got != want {
t.Fatalf("sync Snapshot() = %#v, %t; want %#v, true", got, ok, want)
}
}
func TestStatusStoreIgnoresOlderGeneration(t *testing.T) {
store := NewStatusStore()
want := Status{Unit: UnitSync, State: StatePlaying, Generation: 3}
store.Observe(want)
store.Observe(Status{Unit: UnitVideo, State: StateIdle, Generation: 2})
if _, ok := store.Snapshot(UnitVideo); ok {
t.Fatal("older video status was stored")
}
if got, ok := store.Snapshot(UnitSync); !ok || got != want {
t.Fatalf("sync Snapshot() = %#v, %t; want %#v, true", got, ok, want)
}
}
func TestStatusStoreKeepsEqualGenerationUnitsIndependent(t *testing.T) {
store := NewStatusStore()
wantVideo := Status{Unit: UnitVideo, State: StatePlaying, Generation: 4}
wantAudio := Status{Unit: UnitAudio, State: StateReconnecting, Generation: 4}
store.Observe(wantVideo)
store.Observe(wantAudio)
if got, ok := store.Snapshot(UnitVideo); !ok || got != wantVideo {
t.Fatalf("video Snapshot() = %#v, %t", got, ok)
}
if got, ok := store.Snapshot(UnitAudio); !ok || got != wantAudio {
t.Fatalf("audio Snapshot() = %#v, %t", got, ok)
}
}