mirror of
https://github.com/livekit/livekit.git
synced 2026-05-23 23:26:16 +00:00
some tests
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user