Files
livekit/test/singlenode_test.go

100 lines
2.2 KiB
Go

package test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClientCouldConnect(t *testing.T) {
if testing.Short() {
t.SkipNow()
return
}
s := setupSingleNodeTest(testRoom)
defer func() {
teardownTest(s, testRoom)
}()
c1 := createRTCClient("c1", defaultServerPort)
c2 := createRTCClient("c2", defaultServerPort)
waitUntilConnected(t, c1, c2)
// ensure they both see each other
withTimeout(t, "c1 and c2 could connect", func() bool {
if len(c1.RemoteParticipants()) == 0 || len(c2.RemoteParticipants()) == 0 {
return false
}
//assert.Equal()
return true
})
}
func TestSinglePublisher(t *testing.T) {
if testing.Short() {
t.SkipNow()
return
}
s := setupSingleNodeTest(testRoom)
defer func() {
teardownTest(s, testRoom)
}()
c1 := createRTCClient("c1", defaultServerPort)
c2 := createRTCClient("c2", defaultServerPort)
waitUntilConnected(t, c1, c2)
// publish a track and ensure clients receive it ok
t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcam")
assert.NoError(t, err)
defer t1.Stop()
t2, err := c1.AddStaticTrack("video/vp8", "video", "webcam")
assert.NoError(t, err)
defer t2.Stop()
// a new client joins and should get the initial stream
c3 := createRTCClient("c3", defaultServerPort)
success := withTimeout(t, "c2 should receive two tracks", func() bool {
if len(c2.SubscribedTracks()) == 0 {
return false
}
// should have received two tracks
if len(c2.SubscribedTracks()[c1.ID()]) != 2 {
return false
}
tr1 := c2.SubscribedTracks()[c1.ID()][0]
assert.Equal(t, c1.ID(), tr1.StreamID())
return true
})
if !success {
t.FailNow()
}
// ensure that new client that has joined also received tracks
waitUntilConnected(t, c3)
success = withTimeout(t, "c2 should receive two tracks", func() bool {
if len(c3.SubscribedTracks()) == 0 {
return false
}
// should have received two tracks
if len(c3.SubscribedTracks()[c1.ID()]) != 2 {
return false
}
return true
})
if !success {
t.FailNow()
}
// ensure that the track ids are generated by server
tracks := c3.SubscribedTracks()[c1.ID()]
for _, tr := range tracks {
assert.True(t, strings.HasPrefix(tr.ID(), "TR_"), "track should begin with TR")
}
}