From 4214ea4c2b57858cffb2da6fd10190140f1fd0d3 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Wed, 6 Sep 2023 16:51:39 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BC=98=E5=8C=96=20server=20=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E5=B9=B6=E5=8F=91=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/server_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/server_test.go b/server/server_test.go index 3b056e0..d7ca8b1 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -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) } }() })