Implemented atomic session replacement.
This commit is contained in:
@@ -240,6 +240,39 @@ func TestSessionControllerUpdatesOnlyChangedIndependentSlot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionControllerReplacesSynchronizedPairWithOneCommand(t *testing.T) {
|
||||
events := make(chan controllerEvent, 32)
|
||||
controller := newRecordingController(t, events)
|
||||
initial := validCommandSession()
|
||||
commands := make(chan SessionCommand)
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- controller.Run(context.Background(), initial, commands) }()
|
||||
start := receiveControllerEvent(t, events)
|
||||
if start.unit != UnitSync || start.action != "start" {
|
||||
t.Fatalf("initial event = %+v, want sync start", start)
|
||||
}
|
||||
|
||||
next := initial
|
||||
next.Video = FeedConfig{Domain: "/next", UUID: "next-video", Active: true}
|
||||
next.Audio = FeedConfig{Domain: "/next", UUID: "next-audio", Active: true}
|
||||
commands <- SessionCommand{Kind: CommandSetSession, Session: next}
|
||||
event := receiveControllerEvent(t, events)
|
||||
wantPair := SyncPairConfig{Video: next.Video, Audio: next.Audio}
|
||||
if event.unit != UnitSync || event.action != "command" || event.pair != wantPair {
|
||||
t.Fatalf("replacement event = %+v, want one sync command for %#v", event, wantPair)
|
||||
}
|
||||
select {
|
||||
case event := <-events:
|
||||
t.Fatalf("atomic replacement emitted an extra event: %+v", event)
|
||||
case <-time.After(20 * time.Millisecond):
|
||||
}
|
||||
|
||||
close(commands)
|
||||
if err := <-done; err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionControllerStopsIndependentSlotsBeforeStartingSync(t *testing.T) {
|
||||
events := make(chan controllerEvent, 32)
|
||||
controller := newRecordingController(t, events)
|
||||
|
||||
Reference in New Issue
Block a user