Improve integration test reliability, wait for RedisRouter to start

This commit is contained in:
David Zhao
2021-06-09 09:51:44 -07:00
parent f6bafc4a01
commit bbf7f83784
+14 -3
View File
@@ -246,9 +246,18 @@ func (r *RedisRouter) Start() error {
if !r.isStarted.TrySet(true) { if !r.isStarted.TrySet(true) {
return nil return nil
} }
workerStarted := make(chan struct{})
go r.statsWorker() go r.statsWorker()
go r.redisWorker() go r.redisWorker(workerStarted)
return nil
// wait until worker is running
select {
case <-workerStarted:
return nil
case <-time.After(3 * time.Second):
return errors.New("Unable to start redis router")
}
} }
func (r *RedisRouter) Stop() { func (r *RedisRouter) Stop() {
@@ -309,7 +318,7 @@ func (r *RedisRouter) statsWorker() {
} }
// worker that consumes redis messages intended for this node // worker that consumes redis messages intended for this node
func (r *RedisRouter) redisWorker() { func (r *RedisRouter) redisWorker(startedChan chan struct{}) {
defer func() { defer func() {
logger.Debugw("finishing redisWorker", "node", r.currentNode.Id) logger.Debugw("finishing redisWorker", "node", r.currentNode.Id)
}() }()
@@ -318,6 +327,8 @@ func (r *RedisRouter) redisWorker() {
sigChannel := signalNodeChannel(r.currentNode.Id) sigChannel := signalNodeChannel(r.currentNode.Id)
rtcChannel := rtcNodeChannel(r.currentNode.Id) rtcChannel := rtcNodeChannel(r.currentNode.Id)
r.pubsub = r.rc.Subscribe(r.ctx, sigChannel, rtcChannel) r.pubsub = r.rc.Subscribe(r.ctx, sigChannel, rtcChannel)
close(startedChan)
for msg := range r.pubsub.Channel() { for msg := range r.pubsub.Channel() {
if msg == nil { if msg == nil {
return return