Skip to content

Commit e4879ab

Browse files
univerionhooyr
authored andcommittedOct 19, 2023
conn_test: Add TestConcurrentClosePing
Updates #298
1 parent 8abed3a commit e4879ab

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
 

‎conn_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -553,3 +553,26 @@ func assertClose(tb testing.TB, c *websocket.Conn) {
553553
err := c.Close(websocket.StatusNormalClosure, "")
554554
assert.Success(tb, err)
555555
}
556+
557+
func TestConcurrentClosePing(t *testing.T) {
558+
t.Parallel()
559+
for i := 0; i < 64; i++ {
560+
func() {
561+
c1, c2 := wstest.Pipe(nil, nil)
562+
defer c1.CloseNow()
563+
defer c2.CloseNow()
564+
c1.CloseRead(context.Background())
565+
c2.CloseRead(context.Background())
566+
go func() {
567+
for range time.Tick(time.Millisecond) {
568+
if err := c1.Ping(context.Background()); err != nil {
569+
return
570+
}
571+
}
572+
}()
573+
574+
time.Sleep(10 * time.Millisecond)
575+
assert.Success(t, c1.Close(websocket.StatusNormalClosure, ""))
576+
}()
577+
}
578+
}

0 commit comments

Comments
 (0)
Please sign in to comment.