Skip to content

Commit a1fadaa

Browse files
author
Mateusz
committed
fix: synchronize stream recv test helper
1 parent dd063fa commit a1fadaa

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

internal/core/stream/recv_context_contract_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type sdkLikeRecvBlocker struct {
1616
mu sync.Mutex
1717
ch chan struct{}
1818
recvStarted chan struct{}
19+
startedOnce sync.Once
1920
}
2021

2122
func newSDKLikeRecvBlocker() *sdkLikeRecvBlocker {
@@ -29,11 +30,14 @@ func (s *sdkLikeRecvBlocker) Recv(ctx context.Context) (lipapi.Event, error) {
2930
if ctx == nil {
3031
return lipapi.Event{}, lipapi.ErrNilContext
3132
}
32-
select {
33-
case s.recvStarted <- struct{}{}:
34-
default:
33+
s.startedOnce.Do(func() { close(s.recvStarted) })
34+
s.mu.Lock()
35+
ch := s.ch
36+
s.mu.Unlock()
37+
if ch == nil {
38+
return lipapi.Event{}, context.Canceled
3539
}
36-
<-s.ch
40+
<-ch
3741
return lipapi.Event{}, context.Canceled
3842
}
3943

0 commit comments

Comments
 (0)