Skip to content

Commit dc5742f

Browse files
authored
Fix race condition on TestConnectionAllowsConcurrentWrites (#282)
Signed-off-by: Paschalis Tsilias <[email protected]>
1 parent 1a9603e commit dc5742f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

server/serverimpl_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -807,12 +807,14 @@ func TestDecodeMessage(t *testing.T) {
807807
}
808808

809809
func TestConnectionAllowsConcurrentWrites(t *testing.T) {
810+
ch := make(chan struct{})
810811
srvConnVal := atomic.Value{}
811812
callbacks := CallbacksStruct{
812813
OnConnectingFunc: func(request *http.Request) types.ConnectionResponse {
813814
return types.ConnectionResponse{Accept: true, ConnectionCallbacks: ConnectionCallbacksStruct{
814815
OnConnectedFunc: func(ctx context.Context, conn types.Connection) {
815816
srvConnVal.Store(conn)
817+
ch <- struct{}{}
816818
},
817819
}}
818820
},
@@ -837,10 +839,7 @@ func TestConnectionAllowsConcurrentWrites(t *testing.T) {
837839
select {
838840
case <-timeout.Done():
839841
t.Error("Client failed to connect before timeout")
840-
default:
841-
if _, ok := srvConnVal.Load().(types.Connection); ok == true {
842-
break
843-
}
842+
case <-ch:
844843
}
845844

846845
cancel()

0 commit comments

Comments
 (0)