Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Jan 6, 2023
1 parent 625c577 commit 94b0453
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
vendor/
bin/
examples/debug/
examples/testsuite/reports
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ bench:

build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/gws-server-linux-amd64 github.com/lxzan/gws/examples/testsuite

testsuite-server:
go run github.com/lxzan/gws/examples/testsuite
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,35 @@ func (c *WebSocket) OnMessage(socket *gws.Conn, message *gws.Message) {
message.Close()
}
```

#### HeartBeat
```go
const PingInterval = 5*time.Second

type WebSocket struct {}

func (c *WebSocket) OnOpen(socket *gws.Conn) {
socket.SetDeadline(time.Now().Add(3*PingInterval))
}

func (c *WebSocket) OnPing(socket *gws.Conn, payload []byte) {
socket.WritePong(nil)
socket.SetDeadline(time.Now().Add(3*PingInterval))
}
```

#### Test
```bash
// Terminal 1
git clone https://github.com/lxzan/gws.git
cd gws
go run github.com/lxzan/gws/examples/testsuite

// Terminal 2
cd examples/testsuite
docker run -it --rm \
-v ${PWD}/config:/config \
-v ${PWD}/reports:/reports \
crossbario/autobahn-testsuite \
wstest -m fuzzingclient -s /config/fuzzingclient.json
```
11 changes: 11 additions & 0 deletions examples/testsuite/config/fuzzingclient.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"outdir": "./reports/servers",
"servers": [
{
"url": "ws://127.0.0.1:3000/connect"
}
],
"cases": ["*"],
"exclude-cases": [],
"exclude-agent-cases": {}
}

0 comments on commit 94b0453

Please sign in to comment.