Skip to content

Commit

Permalink
Fix race condition on TestConnectionAllowsConcurrentWrites (#282)
Browse files Browse the repository at this point in the history
Signed-off-by: Paschalis Tsilias <paschalis.tsilias@grafana.com>
  • Loading branch information
tpaschalis authored Jun 8, 2024
1 parent 1a9603e commit dc5742f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions server/serverimpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,14 @@ func TestDecodeMessage(t *testing.T) {
}

func TestConnectionAllowsConcurrentWrites(t *testing.T) {
ch := make(chan struct{})
srvConnVal := atomic.Value{}
callbacks := CallbacksStruct{
OnConnectingFunc: func(request *http.Request) types.ConnectionResponse {
return types.ConnectionResponse{Accept: true, ConnectionCallbacks: ConnectionCallbacksStruct{
OnConnectedFunc: func(ctx context.Context, conn types.Connection) {
srvConnVal.Store(conn)
ch <- struct{}{}
},
}}
},
Expand All @@ -837,10 +839,7 @@ func TestConnectionAllowsConcurrentWrites(t *testing.T) {
select {
case <-timeout.Done():
t.Error("Client failed to connect before timeout")
default:
if _, ok := srvConnVal.Load().(types.Connection); ok == true {
break
}
case <-ch:
}

cancel()
Expand Down

0 comments on commit dc5742f

Please sign in to comment.