Skip to content

Commit

Permalink
test: 优化 server 服务器并发测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Sep 6, 2023
1 parent 3e35e73 commit 4214ea4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/kercylan98/minotaur/server/client"
"github.com/kercylan98/minotaur/utils/times"
"golang.org/x/time/rate"
"sync/atomic"
"testing"
"time"
)
Expand All @@ -31,17 +30,21 @@ func TestNew(t *testing.T) {
}

func TestNewClient(t *testing.T) {
var total atomic.Int64
for i := 0; i < 1000; i++ {
id := i
fmt.Println("启动", i+1)
cli := client.NewWebsocket("ws://127.0.0.1:9999")
cli.RegConnectionReceivePacketEvent(func(conn *client.Client, wst int, packet []byte) {
fmt.Println(string(packet))
fmt.Println("收到", id+1, string(packet))
})
cli.RegConnectionOpenedEvent(func(conn *client.Client) {
go func() {
for i < 1000 {
time.Sleep(time.Second)
}
for {
time.Sleep(time.Millisecond * 100)
cli.WriteWS(2, []byte("hello"))
total.Add(1)
}
}()
})
Expand Down

0 comments on commit 4214ea4

Please sign in to comment.