mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-05-02 14:02:44 +02:00
Add lock for TestClient connections to support writing from multiple goroutines.
This commit is contained in:
parent
8e98ad3438
commit
225f5bbd97
|
@ -34,6 +34,7 @@ import (
|
|||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -211,6 +212,7 @@ type TestClient struct {
|
|||
hub *Hub
|
||||
server *httptest.Server
|
||||
|
||||
mu sync.Mutex
|
||||
conn *websocket.Conn
|
||||
localAddr net.Addr
|
||||
|
||||
|
@ -280,6 +282,8 @@ func (c *TestClient) CloseWithBye() {
|
|||
}
|
||||
|
||||
func (c *TestClient) Close() {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if err := c.conn.WriteMessage(websocket.CloseMessage, []byte{}); err == websocket.ErrCloseSent {
|
||||
// Already closed
|
||||
return
|
||||
|
@ -368,6 +372,8 @@ func (c *TestClient) WriteJSON(data interface{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.conn.WriteJSON(data)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue