Wait for close message to be processed in test client before closing.

This commit is contained in:
Joachim Bauch 2021-06-07 17:08:02 +02:00
parent 447fa9a279
commit 9a473b9bf1
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02

View file

@ -227,7 +227,13 @@ func (c *TestClient) CloseWithBye() {
}
func (c *TestClient) Close() {
c.conn.WriteMessage(websocket.CloseMessage, []byte{}) // nolint
if err := c.conn.WriteMessage(websocket.CloseMessage, []byte{}); err == websocket.ErrCloseSent {
// Already closed
return
}
// Wait a bit for close message to be processed.
time.Sleep(100 * time.Millisecond)
c.conn.Close()
// Drain any entries in the channels to terminate the read goroutine.