From e4879ab74e5dd045a4ef5707f2c542b9cf4a4321 Mon Sep 17 00:00:00 2001 From: univerio Date: Thu, 25 May 2023 12:34:29 +0200 Subject: [PATCH] conn_test: Add TestConcurrentClosePing Updates #298 --- conn_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/conn_test.go b/conn_test.go index c814ca28..3df6c64a 100644 --- a/conn_test.go +++ b/conn_test.go @@ -553,3 +553,26 @@ func assertClose(tb testing.TB, c *websocket.Conn) { err := c.Close(websocket.StatusNormalClosure, "") assert.Success(tb, err) } + +func TestConcurrentClosePing(t *testing.T) { + t.Parallel() + for i := 0; i < 64; i++ { + func() { + c1, c2 := wstest.Pipe(nil, nil) + defer c1.CloseNow() + defer c2.CloseNow() + c1.CloseRead(context.Background()) + c2.CloseRead(context.Background()) + go func() { + for range time.Tick(time.Millisecond) { + if err := c1.Ping(context.Background()); err != nil { + return + } + } + }() + + time.Sleep(10 * time.Millisecond) + assert.Success(t, c1.Close(websocket.StatusNormalClosure, "")) + }() + } +}