Skip to content

Commit

Permalink
perf: reduce timer in write_control
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
  • Loading branch information
rfyiamcool authored and AlexVulaj committed Aug 4, 2024
1 parent f01629e commit c5b8b8c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
const message = "this is a ping/pong message"
for _, isServer := range []bool{true, false} {
Expand Down

0 comments on commit c5b8b8c

Please sign in to comment.