Skip to content

Commit

Permalink
加测试代码
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Mar 11, 2024
1 parent 7b88b41 commit 7401558
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
29 changes: 28 additions & 1 deletion autobahn/autobahn-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ var certPEMBlock []byte
//go:embed privatekey.pem
var keyPEMBlock []byte

type echoHandler struct{}
type echoHandler struct {
openWriteTimeout bool
}

func (e *echoHandler) OnOpen(c *quickws.Conn) {
fmt.Printf("OnOpen: %p\n", c)
Expand All @@ -33,6 +35,13 @@ func (e *echoHandler) OnMessage(c *quickws.Conn, op quickws.Opcode, msg []byte)
// if err := c.WriteTimeout(op, msg, 3*time.Second); err != nil {
// fmt.Println("write fail:", err)
// }

if e.openWriteTimeout {
if err := c.WriteTimeout(op, msg, 50*time.Second); err != nil {
fmt.Println("write fail:", err)
}
return
}
if err := c.WriteMessage(op, msg); err != nil {
fmt.Println("write fail:", err)
}
Expand Down Expand Up @@ -60,9 +69,27 @@ func echo(w http.ResponseWriter, r *http.Request) {
c.ReadLoop()
}

func echo2(w http.ResponseWriter, r *http.Request) {
c, err := quickws.Upgrade(w, r,
quickws.WithServerReplyPing(),
quickws.WithServerDecompression(),
quickws.WithServerIgnorePong(),
quickws.WithServerCallback(&echoHandler{openWriteTimeout: true}),
quickws.WithServerEnableUTF8Check(),
quickws.WithServerReadTimeout(5*time.Second),
)
if err != nil {
fmt.Println("Upgrade fail:", err)
return
}

c.ReadLoop()
}

func main() {
mux := &http.ServeMux{}
mux.HandleFunc("/autobahn", echo)
mux.HandleFunc("/autobahn-timeout", echo)

rawTCP, err := net.Listen("tcp", ":9001")
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions autobahn/config/fuzzingclient.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"version": 18
}
},
{
"agent": "non-tls-timeout",
"url": "ws://localhost:9001/autobahn-timeout",
"options": {
"version": 18
}
},
{
"agent": "tls",
"url": "wss://localhost:9002/autobahn",
Expand All @@ -23,5 +30,4 @@
""
],
"exclude-agent-cases": {}
}

}
1 change: 1 addition & 0 deletions autobahn/run_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker run -it --rm --net=host -v ${PWD}/config:/config -v ${PWD}/report:/report crossbario/autobahn-testsuite wstest -m fuzzingclient -s /config/fuzzingclient.json

0 comments on commit 7401558

Please sign in to comment.