Use a participant worker queue in room. (#2420)

* Use a participant worker queue in room.

Removes selectively needing to call things in goroutine from
participant.

Also, a bit of drive-by clean up.

* spelling

* prevent race

* don't need to remove in goroutine as it is already running in the worker

* worker will get cleaned up in state change callback

* create participant worker only if not created already

* ref count participant worker

* maintain participant list

* clean up oldState
This commit is contained in:
Raja Subramanian
2024-01-28 22:10:35 +05:30
committed by GitHub
parent 38352b6125
commit bcf9fe3f0f
12 changed files with 265 additions and 274 deletions
+6 -8
View File
@@ -110,8 +110,7 @@ func TestRoomJoin(t *testing.T) {
stateChangeCB := p.OnStateChangeArgsForCall(0)
require.NotNil(t, stateChangeCB)
p.StateReturns(livekit.ParticipantInfo_ACTIVE)
stateChangeCB(p, livekit.ParticipantInfo_JOINED)
stateChangeCB(p, livekit.ParticipantInfo_ACTIVE)
// it should become a subscriber when connectivity changes
numTracks := 0
@@ -122,7 +121,7 @@ func TestRoomJoin(t *testing.T) {
numTracks += len(op.GetPublishedTracks())
}
require.Equal(t, numTracks, p.SubscribeToTrackCallCount())
require.Eventually(t, func() bool { return p.SubscribeToTrackCallCount() == numTracks }, 5*time.Second, 10*time.Millisecond)
})
t.Run("participant state change is broadcasted to others", func(t *testing.T) {
@@ -218,7 +217,7 @@ func TestParticipantUpdate(t *testing.T) {
expected += 1
}
fp := p.(*typesfakes.FakeLocalParticipant)
require.Equal(t, expected, fp.SendParticipantUpdateCallCount())
require.Eventually(t, func() bool { return fp.SendParticipantUpdateCallCount() == expected }, 5*time.Second, 10*time.Millisecond)
}
})
}
@@ -424,8 +423,8 @@ func TestNewTrack(t *testing.T) {
require.NotNil(t, trackCB)
trackCB(pub, track)
// only p1 should've been subscribed to
require.Eventually(t, func() bool { return p1.SubscribeToTrackCallCount() == 1 }, 5*time.Second, 10*time.Millisecond)
require.Equal(t, 0, p0.SubscribeToTrackCallCount())
require.Equal(t, 1, p1.SubscribeToTrackCallCount())
})
}
@@ -679,10 +678,9 @@ func TestHiddenParticipants(t *testing.T) {
stateChangeCB := hidden.OnStateChangeArgsForCall(0)
require.NotNil(t, stateChangeCB)
hidden.StateReturns(livekit.ParticipantInfo_ACTIVE)
stateChangeCB(hidden, livekit.ParticipantInfo_JOINED)
stateChangeCB(hidden, livekit.ParticipantInfo_ACTIVE)
require.Equal(t, 2, hidden.SubscribeToTrackCallCount())
require.Eventually(t, func() bool { return hidden.SubscribeToTrackCallCount() == 2 }, 5*time.Second, 10*time.Millisecond)
})
}