mirror of https://github.com/gorilla/websocket.git
perf: reduce timer in write_control
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
This commit is contained in:
parent
d15aba1e61
commit
d08ee1ad9b
25
conn_test.go
25
conn_test.go
|
@ -148,6 +148,31 @@ func TestFraming(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConcurrencyWriteControl(t *testing.T) {
|
||||||
|
const message = "this is a ping/pong messsage"
|
||||||
|
loop := 10
|
||||||
|
workers := 10
|
||||||
|
for i := 0; i < loop; i++ {
|
||||||
|
var connBuf bytes.Buffer
|
||||||
|
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wc := newTestConn(nil, &connBuf, true)
|
||||||
|
|
||||||
|
for i := 0; i < workers; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
if err := wc.WriteControl(PongMessage, []byte(message), time.Now().Add(time.Second)); err != nil {
|
||||||
|
t.Errorf("concurrently wc.WriteControl() returned %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
wc.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestControl(t *testing.T) {
|
func TestControl(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
const message = "this is a ping/pong messsage"
|
const message = "this is a ping/pong messsage"
|
||||||
|
|
Loading…
Reference in New Issue