switch to a single redis subscriber, close properly

This commit is contained in:
David Zhao
2021-02-04 00:25:09 -08:00
parent 5dec5b1ae2
commit c015e267b0
7 changed files with 125 additions and 131 deletions
+13 -3
View File
@@ -9,7 +9,6 @@ import (
"time"
"github.com/go-redis/redis/v8"
"github.com/stretchr/testify/assert"
"github.com/twitchtv/twirp"
"github.com/livekit/livekit-server/cmd/cli/client"
@@ -122,17 +121,28 @@ func withTimeout(t *testing.T, description string, f func() bool) bool {
func waitUntilConnected(t *testing.T, clients ...*client.RTCClient) {
logger.Infow("waiting for clients to become connected")
wg := sync.WaitGroup{}
errChan := make(chan error, len(clients))
for i := range clients {
c := clients[i]
wg.Add(1)
go func() {
defer wg.Done()
if !assert.NoError(t, c.WaitUntilConnected()) {
t.Fatal("client could not connect", c.ID())
err := c.WaitUntilConnected()
if err != nil {
errChan <- err
}
}()
}
wg.Wait()
close(errChan)
hasError := false
for err := range errChan {
t.Fatal(err)
hasError = true
}
if hasError {
t.FailNow()
}
}
func createSingleNodeServer() *service.LivekitServer {
+7 -5
View File
@@ -1,7 +1,6 @@
package test
import (
"math/rand"
"testing"
"time"
@@ -13,9 +12,11 @@ import (
// a scenario with lots of clients connecting, publishing, and leaving at random periods
func scenarioPublishingUponJoining(t *testing.T, ports ...int) {
c1 := createRTCClient("puj_1", ports[rand.Intn(len(ports))])
c2 := createRTCClient("puj_2", ports[rand.Intn(len(ports))])
c3 := createRTCClient("puj_3", ports[rand.Intn(len(ports))])
firstPort := ports[0]
lastPort := ports[len(ports)-1]
c1 := createRTCClient("puj_1", firstPort)
c2 := createRTCClient("puj_2", lastPort)
c3 := createRTCClient("puj_3", firstPort)
defer stopClients(c1, c2, c3)
waitUntilConnected(t, c1, c2, c3)
@@ -63,7 +64,8 @@ func scenarioPublishingUponJoining(t *testing.T, ports ...int) {
}
logger.Infow("c2 reconnecting")
c2 = createRTCClient("puj_2", ports[rand.Intn(len(ports))])
// connect to a diff port
c2 = createRTCClient("puj_2", firstPort)
defer c2.Stop()
waitUntilConnected(t, c2)
writers = publishTracksForClients(t, c2)