Skip to content

Commit

Permalink
Use chan to sync test
Browse files Browse the repository at this point in the history
  • Loading branch information
dkeysil committed Jan 29, 2024
1 parent 1fdb438 commit 838e2a6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions services/components/botio/bot_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ func (s *BotClientSuite) TestStartProcessStop() {
s.lifecycleMetrics.EXPECT().ActionSubscribe(combinerSubscriptions)

// test health checks
healthCheckChan := make(chan interface{})
HealthCheckInterval = time.Second
s.botGrpc.EXPECT().DoHealthCheck(gomock.Any()).MinTimes(1)
s.lifecycleMetrics.EXPECT().HealthCheckAttempt(s.botClient.configUnsafe).MinTimes(1)
s.lifecycleMetrics.EXPECT().HealthCheckSuccess(s.botClient.configUnsafe).MinTimes(1)
s.lifecycleMetrics.EXPECT().HealthCheckSuccess(s.botClient.configUnsafe).Do(func(_ interface{}) {
close(healthCheckChan)
}).MinTimes(1)

s.msgClient.EXPECT().Publish(messaging.SubjectAgentsAlertSubscribe, combinerSubscriptions)
s.botClient.StartProcessing()
Expand Down Expand Up @@ -193,8 +196,7 @@ func (s *BotClientSuite) TestStartProcessStop() {
s.lifecycleMetrics.EXPECT().ActionUnsubscribe(combinerSubscriptions)

s.r.NoError(s.botClient.Close())
// Using small sleep to allow goroutines to be executed (e.g. health check)
time.Sleep(30 * time.Millisecond)
<-healthCheckChan
}

func (s *BotClientSuite) TestCombinerBotSubscriptions() {
Expand Down

0 comments on commit 838e2a6

Please sign in to comment.