Improve readability of test failures (#386)

This commit is contained in:
David Zhao
2022-01-28 21:34:21 -08:00
committed by GitHub
parent 5b57522c05
commit 6af6eefb8c
9 changed files with 198 additions and 147 deletions
+52 -49
View File
@@ -35,8 +35,14 @@ func TestClientCouldConnect(t *testing.T) {
waitUntilConnected(t, c1, c2)
// ensure they both see each other
testutils.WithTimeout(t, "c1 and c2 could connect", func() bool {
return len(c1.RemoteParticipants()) != 0 && len(c2.RemoteParticipants()) != 0
testutils.WithTimeout(t, func() string {
if len(c1.RemoteParticipants()) == 0 {
return "c1 did not see c2"
}
if len(c2.RemoteParticipants()) == 0 {
return "c2 did not see c1"
}
return ""
})
}
@@ -70,13 +76,13 @@ func TestClientConnectDuplicate(t *testing.T) {
opts := &testclient.Options{
Publish: "duplicate_connection",
}
success := testutils.WithTimeout(t, "c2 should receive two tracks", func() bool {
testutils.WithTimeout(t, func() string {
if len(c2.SubscribedTracks()) == 0 {
return false
return "c2 didn't subscribe to anything"
}
// should have received three tracks
if len(c2.SubscribedTracks()[c1.ID()]) != 2 {
return false
return "c2 didn't subscribe to both tracks from c1"
}
// participant ID can be appended with '#..' . but should contain orig id as prefix
@@ -86,11 +92,8 @@ func TestClientConnectDuplicate(t *testing.T) {
tr2 := c2.SubscribedTracks()[c1.ID()][1]
participantId2, _ := rtc.UnpackStreamID(tr2.StreamID())
require.Equal(t, c1.ID(), participantId2)
return true
return ""
})
if !success {
t.FailNow()
}
c1Dup := createRTCClientWithToken(token, defaultServerPort, opts)
@@ -100,20 +103,17 @@ func TestClientConnectDuplicate(t *testing.T) {
require.NoError(t, err)
defer t3.Stop()
success = testutils.WithTimeout(t, "c2 should receive third tracks", func() bool {
testutils.WithTimeout(t, func() string {
if len(c2.SubscribedTracks()[c1Dup.ID()]) != 1 {
return false
return "c2 was not subscribed to track from duplicated c1"
}
tr3 := c2.SubscribedTracks()[c1Dup.ID()][0]
participantId3, _ := rtc.UnpackStreamID(tr3.StreamID())
require.Contains(t, c1Dup.ID(), participantId3)
return true
return ""
})
if !success {
t.FailNow()
}
}
func TestSinglePublisher(t *testing.T) {
@@ -137,19 +137,19 @@ func TestSinglePublisher(t *testing.T) {
require.NoError(t, err)
defer t2.Stop()
testutils.WithTimeout(t, "c2 should receive two tracks", func() bool {
testutils.WithTimeout(t, func() string {
if len(c2.SubscribedTracks()) == 0 {
return false
return "c2 was not subscribed to anything"
}
// should have received two tracks
if len(c2.SubscribedTracks()[c1.ID()]) != 2 {
return false
return "c2 didn't subscribe to both tracks from c1"
}
tr1 := c2.SubscribedTracks()[c1.ID()][0]
participantId, _ := rtc.UnpackStreamID(tr1.StreamID())
require.Equal(t, c1.ID(), participantId)
return true
return ""
})
// ensure mime type is received
remoteC1 := c2.GetRemoteParticipant(c1.ID())
@@ -163,15 +163,15 @@ func TestSinglePublisher(t *testing.T) {
// ensure that new client that has joined also received tracks
waitUntilConnected(t, c3)
testutils.WithTimeout(t, "c3 should receive two tracks", func() bool {
testutils.WithTimeout(t, func() string {
if len(c3.SubscribedTracks()) == 0 {
return false
return "c3 didn't subscribe to anything"
}
// should have received two tracks
if len(c3.SubscribedTracks()[c1.ID()]) != 2 {
return false
return "c3 didn't subscribe to tracks from c1"
}
return true
return ""
})
// ensure that the track ids are generated by server
@@ -183,19 +183,17 @@ func TestSinglePublisher(t *testing.T) {
// when c3 disconnects, ensure subscriber is cleaned up correctly
c3.Stop()
testutils.WithTimeout(t, "c3 is cleaned up as a subscriber", func() bool {
testutils.WithTimeout(t, func() string {
room := s.RoomManager().GetRoom(context.Background(), testRoom)
require.NotNil(t, room)
p := room.GetParticipant("c1")
require.NotNil(t, p)
for _, t := range p.GetPublishedTracks() {
if t.IsSubscriber(c3.ID()) {
return false
return "c3 was not a subscriber of c1's tracks"
}
}
return true
return ""
})
}
@@ -245,26 +243,24 @@ func Test_RenegotiationWithDifferentCodecs(t *testing.T) {
require.NoError(t, err)
defer t2.Stop()
success := testutils.WithTimeout(t, "c2 should receive two tracks, video is vp8", func() bool {
testutils.WithTimeout(t, func() string {
if len(c2.SubscribedTracks()) == 0 {
return false
return "c2 was not subscribed to anything"
}
// should have received two tracks
if len(c2.SubscribedTracks()[c1.ID()]) != 2 {
return false
return "c2 was not subscribed to tracks from c1"
}
tracks := c2.SubscribedTracks()[c1.ID()]
for _, t := range tracks {
if strings.EqualFold(t.Codec().MimeType, "video/vp8") {
return true
return ""
}
}
return false
return "did not receive track with vp8"
})
if !success {
t.FailNow()
}
t3, err := c1.AddStaticTrackWithCodec(webrtc.RTPCodecCapability{
MimeType: "video/h264",
@@ -274,13 +270,13 @@ func Test_RenegotiationWithDifferentCodecs(t *testing.T) {
defer t3.Stop()
require.NoError(t, err)
success = testutils.WithTimeout(t, "c2 should receive two video tracks, one vp8 one h264", func() bool {
testutils.WithTimeout(t, func() string {
if len(c2.SubscribedTracks()) == 0 {
return false
return "c2's not subscribed to anything"
}
// should have received three tracks
if len(c2.SubscribedTracks()[c1.ID()]) != 3 {
return false
return "c2's not subscribed to 3 tracks from c1"
}
var vp8Found, h264Found bool
@@ -292,11 +288,14 @@ func Test_RenegotiationWithDifferentCodecs(t *testing.T) {
h264Found = true
}
}
return vp8Found && h264Found
if !vp8Found {
return "did not receive track with vp8"
}
if !h264Found {
return "did not receive track with h264"
}
return ""
})
if !success {
t.FailNow()
}
}
func TestSingleNodeRoomList(t *testing.T) {
@@ -411,15 +410,15 @@ func TestSingleNodeUpdateSubscriptionPermissions(t *testing.T) {
defer stopWriters(writers...)
// wait sub receives tracks
testutils.WithTimeout(t, "waiting for sub to receive track metadata", func() bool {
testutils.WithTimeout(t, func() string {
pubRemote := sub.GetRemoteParticipant(pub.ID())
if pubRemote == nil {
return false
return "could not find remote publisher"
}
if len(pubRemote.Tracks) != 2 {
return false
return "did not receive metadata for published tracks"
}
return true
return ""
})
// set permissions out of band
@@ -434,8 +433,12 @@ func TestSingleNodeUpdateSubscriptionPermissions(t *testing.T) {
})
require.NoError(t, err)
testutils.WithTimeout(t, "waiting to get subscriptions", func() bool {
testutils.WithTimeout(t, func() string {
tracks := sub.SubscribedTracks()[pub.ID()]
return len(tracks) == 2
if len(tracks) == 2 {
return ""
} else {
return fmt.Sprintf("expected 2 tracks subscribed, actual: %d", len(tracks))
}
})
}