From 66c916b3fc962368f78cb69a68d55f20db0de263 Mon Sep 17 00:00:00 2001 From: guonaihong Date: Sat, 19 Aug 2023 19:50:39 +0800 Subject: [PATCH] =?UTF-8?q?+=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common_options_test.go | 55 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/common_options_test.go b/common_options_test.go index 3c83267..d4327d7 100644 --- a/common_options_test.go +++ b/common_options_test.go @@ -1215,7 +1215,7 @@ func Test_CommonOption(t *testing.T) { } }) - t.Run("13-15.server.local: WithServerBufioMultipleTimesPayloadSize", func(t *testing.T) { + t.Run("13-15.server.local.1: WithServerBufioMultipleTimesPayloadSize", func(t *testing.T) { run := int32(0) data := make(chan string, 1) ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -1260,7 +1260,7 @@ func Test_CommonOption(t *testing.T) { } }) - t.Run("13-15.server.global: WithServerBufioMultipleTimesPayloadSize", func(t *testing.T) { + t.Run("13-15.server.global.2: WithServerBufioMultipleTimesPayloadSize", func(t *testing.T) { run := int32(0) data := make(chan string, 1) upgrade := NewUpgrade(WithServerMaxDelayWriteDuration(time.Millisecond*20), WithServerMaxDelayWriteNum(3), WithServerDelayWriteInitBufferSize(4096), WithServerOnMessageFunc(func(c *Conn, op Opcode, payload []byte) { @@ -1354,6 +1354,57 @@ func Test_CommonOption(t *testing.T) { } }) + t.Run("13-15.client: WithServerBufioMultipleTimesPayloadSize-Compress", func(t *testing.T) { + run := int32(0) + data := make(chan string, 1) + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + c, err := Upgrade(w, r, + WithServerDecompressAndCompress(), + WithServerBufioParseMode(), + WithServerOnMessageFunc(func(c *Conn, op Opcode, payload []byte) { + c.WriteMessage(op, payload) + atomic.AddInt32(&run, int32(1)) + data <- string(payload) + })) + if err != nil { + t.Error(err) + } + c.StartReadLoop() + })) + + defer ts.Close() + + url := strings.ReplaceAll(ts.URL, "http", "ws") + con, err := Dial(url, WithClientDecompressAndCompress(), + WithClientDecompression(), + WithClientMaxDelayWriteDuration(10*time.Millisecond), + WithClientMaxDelayWriteNum(3), + WithClientWindowsParseMode(), + WithClientDelayWriteInitBufferSize(4096), + WithClientOnMessageFunc(func(c *Conn, op Opcode, payload []byte) { + c.WriteMessageDelay(op, []byte("hello")) + c.WriteMessageDelay(op, []byte("hello")) + c.WriteMessageDelay(op, []byte("hello")) + })) + if err != nil { + t.Error(err) + } + defer con.Close() + + con.WriteMessage(Binary, []byte("hello")) + con.StartReadLoop() + select { + case d := <-data: + if d != "hello" { + t.Errorf("write message or read message fail:got:%s, need:hello\n", d) + } + case <-time.After(1000 * time.Millisecond): + } + if atomic.LoadInt32(&run) != 1 { + t.Error("not run server:method fail") + } + }) + t.Run("16.1.WithServerReadTimeout:local-Upgrade", func(t *testing.T) { var tsort testServerOptionReadTimeout