mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-06-10 09:52:12 +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"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -211,6 +212,7 @@ type TestClient struct {
|
||||||
hub *Hub
|
hub *Hub
|
||||||
server *httptest.Server
|
server *httptest.Server
|
||||||
|
|
||||||
|
mu sync.Mutex
|
||||||
conn *websocket.Conn
|
conn *websocket.Conn
|
||||||
localAddr net.Addr
|
localAddr net.Addr
|
||||||
|
|
||||||
|
@ -280,6 +282,8 @@ func (c *TestClient) CloseWithBye() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestClient) Close() {
|
func (c *TestClient) Close() {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
if err := c.conn.WriteMessage(websocket.CloseMessage, []byte{}); err == websocket.ErrCloseSent {
|
if err := c.conn.WriteMessage(websocket.CloseMessage, []byte{}); err == websocket.ErrCloseSent {
|
||||||
// Already closed
|
// Already closed
|
||||||
return
|
return
|
||||||
|
@ -368,6 +372,8 @@ func (c *TestClient) WriteJSON(data interface{}) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
return c.conn.WriteJSON(data)
|
return c.conn.WriteJSON(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue