Skip to content

Commit 89d5415

Browse files
committed
broadcastclient_test: avoid deadlock in test
1 parent 189912a commit 89d5415

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

broadcastclient/broadcastclient_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,21 @@ func startMakeBroadcastClient(ctx context.Context, t *testing.T, clientConfig Co
232232

233233
go func() {
234234
defer wg.Done()
235-
defer broadcastClient.StopAndWait()
235+
// drain messages so messages could be sent on ts.messageReceiver
236+
defer func() {
237+
clientDone := make(chan struct{})
238+
go func() {
239+
for {
240+
select {
241+
case <-ts.messageReceiver:
242+
case <-clientDone:
243+
return
244+
}
245+
}
246+
}()
247+
broadcastClient.StopAndWait()
248+
close(clientDone)
249+
}()
236250
var timeout time.Duration
237251
if expectedCount == 0 {
238252
timeout = 1 * time.Second

0 commit comments

Comments
 (0)