Skip to content

Commit

Permalink
conn_test: Add TestConcurrentClosePing
Browse files Browse the repository at this point in the history
Updates #298
  • Loading branch information
univerio authored and nhooyr committed Oct 19, 2023
1 parent 8abed3a commit e4879ab
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions conn_test.go
Expand Up @@ -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, ""))
}()
}
}

0 comments on commit e4879ab

Please sign in to comment.