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 07de81d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions services/components/botio/bot_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,20 @@ 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.botGrpc.EXPECT().DoHealthCheck(gomock.Any()).Return(nil).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()
s.botClient.Initialize()

<-healthCheckChan

<-s.botClient.Initialized()

txReq := &protocol.EvaluateTxRequest{
Expand Down Expand Up @@ -193,8 +198,6 @@ 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)
}

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

0 comments on commit 07de81d

Please sign in to comment.