Skip to content

Commit

Permalink
加测试代码 (#23)
Browse files Browse the repository at this point in the history
* 加测试代码

* 调试

* 调试

* 更新

* up
  • Loading branch information
guonaihong committed Mar 11, 2024
1 parent 7b88b41 commit 96be249
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/autobahn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
env:
CRYPTOGRAPHY_ALLOW_OPENSSL_102: yes
run: |
chmod +x ./autobahn/script/run.sh & ./autobahn/script/run.sh
chmod +x ./autobahn/script/run.sh && ./autobahn/script/run.sh
- name: Autobahn Report Artifact
if: >-
startsWith(matrix.os, 'ubuntu')
Expand Down
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
7 changes: 4 additions & 3 deletions autobahn/script/run.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

mkdir -p ./autobahn/bin
go build -o ./autobahn/bin/autobahn_server ./autobahn/server/
go build -o ./autobahn/bin/autobahn_reporter ./autobahn/reporter/
go build -o ./autobahn/bin/autobahn_server ./autobahn/autobahn-server.go
# go build -o ./autobahn/bin/autobahn_reporter ./autobahn/reporter/

echo "pwd:" $(pwd)
./autobahn/bin/autobahn_server &
Expand Down Expand Up @@ -34,7 +34,8 @@ cleanup() {
killall autobahn_server
}

./autobahn/bin/autobahn_reporter ${PWD}/autobahn/report/index.json
# TODO
# ./autobahn/bin/autobahn_reporter ${PWD}/autobahn/report/index.json

cleanup

0 comments on commit 96be249

Please sign in to comment.