Skip to content

Commit

Permalink
+测试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Aug 19, 2023
1 parent 5127496 commit 66c916b
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions common_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 66c916b

Please sign in to comment.