some tests

This commit is contained in:
David Zhao
2021-01-12 18:03:08 -08:00
parent bd885b1de9
commit 381ec58050
2 changed files with 33 additions and 1 deletions
+3 -1
View File
@@ -535,7 +535,9 @@ func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) {
p.lock.Lock()
delete(p.publishedTracks, track.ID())
p.lock.Unlock()
p.onTrackUpdated(p, track)
if p.onTrackUpdated != nil {
p.onTrackUpdated(p, track)
}
})
if p.onTrackPublished != nil {
+30
View File
@@ -5,6 +5,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
"github.com/livekit/livekit-server/proto/livekit"
)
@@ -40,3 +42,31 @@ func TestIsReady(t *testing.T) {
})
}
}
func TestTrackPublishEvents(t *testing.T) {
p := newParticipantForTest("test")
track := &typesfakes.FakePublishedTrack{}
track.IDReturns("id")
published := false
updated := false
p.OnTrackUpdated(func(p types.Participant, track types.PublishedTrack) {
updated = true
})
p.OnTrackPublished(func(p types.Participant, track types.PublishedTrack) {
published = true
})
p.handleTrackPublished(track)
assert.True(t, published)
assert.False(t, updated)
assert.Len(t, p.publishedTracks, 1)
track.OnCloseArgsForCall(0)()
assert.Len(t, p.publishedTracks, 0)
assert.True(t, updated)
}
func newParticipantForTest(name string) *ParticipantImpl {
p, _ := NewParticipant(&typesfakes.FakePeerConnection{}, &typesfakes.FakeSignalConnection{}, name, ReceiverConfig{})
return p
}