Skip to content

Commit d6df69e

Browse files
committed
fix test
Signed-off-by: Roman Dmytrenko <[email protected]>
1 parent 9d416d2 commit d6df69e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

internal/server/evaluation/client/server_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,22 @@ func TestServer_EvaluationSnapshotNamespaceStream_ContextCancel(t *testing.T) {
231231
ch := args.Get(2).(chan<- *rpcevaluation.EvaluationNamespaceSnapshot)
232232
go func() {
233233
ch <- &rpcevaluation.EvaluationNamespaceSnapshot{Digest: "d1"}
234-
// simulate context cancel before next send
235-
wait <- struct{}{}
234+
// wait for Send to be called before closing
235+
<-wait
236236
close(ch)
237237
}()
238238
})
239239

240240
ctx, cancel := context.WithCancel(t.Context())
241241
stream := &mockStream{ctx: ctx}
242-
stream.On("Send", mock.Anything).Return(nil)
242+
stream.On("Send", mock.Anything).Return(nil).Run(func(args mock.Arguments) {
243+
// signal that Send was called, then cancel context
244+
wait <- struct{}{}
245+
cancel()
246+
})
243247
s := NewServer(logger, envStore)
244248
req := &rpcevaluation.EvaluationNamespaceSnapshotStreamRequest{EnvironmentKey: "env-key", Key: "ns-key"}
245249

246-
go func() {
247-
<-wait
248-
cancel()
249-
}()
250-
251250
err := s.EvaluationSnapshotNamespaceStream(req, stream)
252251
require.NoError(t, err)
253252
require.GreaterOrEqual(t, len(stream.sent), 1)

0 commit comments

Comments
 (0)