single publisher integration test

This commit is contained in:
David Zhao
2021-01-13 17:38:40 -08:00
parent 233306d83a
commit 9a10a57b30
5 changed files with 166 additions and 48 deletions
+50 -3
View File
@@ -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
})
}