Skip to content

Commit 631c152

Browse files
committed
Fix racey conn.Context test
1 parent 61830e9 commit 631c152

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

websocket_test.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -485,19 +485,14 @@ func TestHandshake(t *testing.T) {
485485
}
486486
defer c.Close(websocket.StatusInternalError, "")
487487

488-
pctx := c.Context(ctx)
488+
cctx := c.Context(ctx)
489489

490-
for ctx.Err() == nil {
491-
err = c.Ping(ctx)
492-
if err != nil {
493-
if pctx.Err() == nil {
494-
return xerrors.Errorf("context from c.Context not cancelled when connection broken")
495-
}
496-
return nil
497-
}
490+
select {
491+
case <-ctx.Done():
492+
return xerrors.Errorf("child context never cancelled")
493+
case <-cctx.Done():
494+
return nil
498495
}
499-
500-
return xerrors.Errorf("all pings succeeded")
501496
},
502497
},
503498
}

0 commit comments

Comments
 (0)