test: 优化 server 服务器并发测试用例

This commit is contained in:
kercylan98 2023-09-06 16:51:39 +08:00
parent 3e35e73c90
commit 4214ea4c2b
1 changed files with 7 additions and 4 deletions

View File

@ -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"
)
@ -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)
}
}()
})