Skip to content

Commit

Permalink
+测试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Aug 22, 2023
1 parent a0afe04 commit ef6501c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,42 @@ func TestFragmentFrame(t *testing.T) {
}
})

t.Run("Ping-FragmentFrame-Fail", func(t *testing.T) {
run := int32(0)
data := make(chan string, 1)
upgrade := NewUpgrade(WithServerBufioParseMode(), WithServerOnCloseFunc(func(c *Conn, err error) {
atomic.AddInt32(&run, int32(1))
data <- err.Error()
}))
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c, err := upgrade.Upgrade(w, r)
if err != nil {
t.Error(err)
}
c.StartReadLoop()
}))

defer ts.Close()

url := strings.ReplaceAll(ts.URL, "http", "ws")
con, err := Dial(url, WithClientDisableBufioClearHack(), WithClientOnMessageFunc(func(c *Conn, mt Opcode, payload []byte) {
}))
if err != nil {
t.Error(err)
}
defer con.Close()

con.writeFragment(Ping, []byte("hello"), 1)
con.StartReadLoop()
select {
case <-data:
case <-time.After(1000 * time.Millisecond):
}
if atomic.LoadInt32(&run) != 1 {
t.Error("not run server:method fail")
}
})

// 分段传递,并且压缩
t.Run("FragmentFrame-Compression", func(t *testing.T) {
run := int32(0)
Expand Down

0 comments on commit ef6501c

Please sign in to comment.