Skip to content

Commit d08ee1a

Browse files
rfyiamcoolAlexVulaj
authored andcommitted
perf: reduce timer in write_control
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
1 parent d15aba1 commit d08ee1a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

conn_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,31 @@ func TestFraming(t *testing.T) {
148148
}
149149
}
150150

151+
func TestConcurrencyWriteControl(t *testing.T) {
152+
const message = "this is a ping/pong messsage"
153+
loop := 10
154+
workers := 10
155+
for i := 0; i < loop; i++ {
156+
var connBuf bytes.Buffer
157+
158+
wg := sync.WaitGroup{}
159+
wc := newTestConn(nil, &connBuf, true)
160+
161+
for i := 0; i < workers; i++ {
162+
wg.Add(1)
163+
go func() {
164+
defer wg.Done()
165+
if err := wc.WriteControl(PongMessage, []byte(message), time.Now().Add(time.Second)); err != nil {
166+
t.Errorf("concurrently wc.WriteControl() returned %v", err)
167+
}
168+
}()
169+
}
170+
171+
wg.Wait()
172+
wc.Close()
173+
}
174+
}
175+
151176
func TestControl(t *testing.T) {
152177
t.Parallel()
153178
const message = "this is a ping/pong messsage"

0 commit comments

Comments
 (0)