single publisher integration test
This commit is contained in:
@@ -4,13 +4,15 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/livekit/livekit-server/cmd/cli/client"
|
||||
"github.com/livekit/livekit-server/pkg/auth"
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/service"
|
||||
"github.com/livekit/livekit-server/proto/livekit"
|
||||
)
|
||||
@@ -55,6 +57,19 @@ func withTimeout(t *testing.T, f func() bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func waitUntilConnected(t *testing.T, clients ...*client.RTCClient) {
|
||||
wg := sync.WaitGroup{}
|
||||
for i := range clients {
|
||||
c := clients[i]
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
assert.NoError(t, c.WaitUntilConnected())
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func createServer() *service.LivekitServer {
|
||||
var err error
|
||||
serverConfig, err = config.NewConfig("")
|
||||
@@ -119,7 +134,6 @@ func (p *StaticKeyProvider) NumKeys() int {
|
||||
|
||||
func (p *StaticKeyProvider) GetSecret(key string) string {
|
||||
if key == testApiKey {
|
||||
logger.GetLogger().Debugf("returning secret: %s", testApiSecret)
|
||||
return testApiSecret
|
||||
}
|
||||
return ""
|
||||
|
||||
@@ -16,13 +16,60 @@ import (
|
||||
|
||||
func TestClientCouldConnect(t *testing.T) {
|
||||
c1 := createClient("c1")
|
||||
assert.NoError(t, c1.WaitUntilConnected())
|
||||
c2 := createClient("c2")
|
||||
assert.NoError(t, c2.WaitUntilConnected())
|
||||
waitUntilConnected(t, c1, c2)
|
||||
|
||||
// ensure they both see each other
|
||||
withTimeout(t, func() bool {
|
||||
return len(c1.RemoteParticipants()) == 1 && len(c2.RemoteParticipants()) == 1
|
||||
if len(c1.RemoteParticipants()) == 0 || len(c2.RemoteParticipants()) == 0 {
|
||||
return false
|
||||
}
|
||||
//assert.Equal()
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func TestSinglePublisher(t *testing.T) {
|
||||
c1 := createClient("c1")
|
||||
c2 := createClient("c2")
|
||||
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 := createClient("c3")
|
||||
|
||||
withTimeout(t, 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, "webcam", tr1.StreamID())
|
||||
return true
|
||||
})
|
||||
|
||||
// ensure that new client that has joined also received tracks
|
||||
waitUntilConnected(t, c3)
|
||||
withTimeout(t, 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
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user