Skip to content

Commit c5b8b8c

Browse files
rfyiamcoolAlexVulaj
authored andcommitted
perf: reduce timer in write_control
Signed-off-by: rfyiamcool <[email protected]>
1 parent f01629e commit c5b8b8c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

conn_test.go

Lines changed: 25 additions & 0 deletions
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
const message = "this is a ping/pong message"
153178
for _, isServer := range []bool{true, false} {

0 commit comments

Comments
 (0)