Skip to content

Commit

Permalink
Merge pull request #19 from lxzan/testing
Browse files Browse the repository at this point in the history
v1.5.1
  • Loading branch information
lxzan authored May 12, 2023
2 parents e9b282f + f6c2337 commit f1f87a1
Show file tree
Hide file tree
Showing 40 changed files with 980 additions and 567 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/autobahn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: autobahn

on:
push:
branches:
- master
- testing
pull_request:
branches:
- master
- testing

jobs:
test:
strategy:
matrix:
os: [ ubuntu-latest ]
go: [ 1.18.x ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Autobahn
env:
CRYPTOGRAPHY_ALLOW_OPENSSL_102: yes
run: |
chmod +x ./autobahn/script/run.sh & ./autobahn/script/run.sh
- name: Autobahn Report Artifact
if: >-
startsWith(matrix.os, 'ubuntu')
uses: actions/upload-artifact@v2

with:
name: autobahn report ${{ matrix.go }} ${{ matrix.os }}
path: autobahn/report
retention-days: 7
31 changes: 31 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
linters:
enable-all: true
# Disable specific linter
# https://golangci-lint.run/usage/linters/#disabled-by-default
disable:
- testpackage
- nosnakecase
- nlreturn
- gomnd
- forcetypeassert
- wsl
- whitespace
- prealloc
- ineffassign
- lll
- funlen
- scopelint
- dupl
- gofumpt
- gofmt
- godot
- gci
- goimports
- gocognit
- ifshort
- gochecknoinits
# Enable presets.
# https://golangci-lint.run/usage/linters
# Run only fast linters from enabled linters set (first run won't be fast)
# Default: false
fast: true
57 changes: 24 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
[10]: https://goreportcard.com/report/github.com/lxzan/gws

- [gws](#gws)
- [event-driven go websocket server](#event-driven-go-websocket-server)
- [Highlight](#highlight)
- [Attention](#attention)
- [Install](#install)
Expand All @@ -35,8 +36,6 @@
- [Upgrade from HTTP](#upgrade-from-http)
- [Unix Domain Socket](#unix-domain-socket)
- [Broadcast](#broadcast)
- [Write JSON](#write-json)
- [Customize Codec](#customize-codec)
- [Autobahn Test](#autobahn-test)
- [Benchmark](#benchmark)
- [Communication](#communication)
Expand Down Expand Up @@ -92,20 +91,25 @@ func main() {
package main

import (
"github.com/klauspost/compress/flate"
"github.com/lxzan/gws"
"time"
)

const PingInterval = 10 * time.Second

func init() {
gws.SetFlateCompressor(128, flate.BestSpeed)
}

func main() {
options := &gws.ServerOption{ReadAsyncEnabled: true, ReadAsyncGoLimit: 4}
options := &gws.ServerOption{ReadAsyncEnabled: true, ReadAsyncGoLimit: 4, CompressEnabled: true}
gws.NewServer(new(Handler), options).Run(":6666")
}

type Handler struct{}

func (c *Handler) OnOpen(socket *gws.Conn) { _ = socket.SetDeadline(time.Now().Add(3 * PingInterval)) }
func (c *Handler) OnOpen(socket *gws.Conn) { _ = socket.SetDeadline(time.Now().Add(2 * PingInterval)) }

func (c *Handler) DeleteSession(socket *gws.Conn) {}

Expand All @@ -114,7 +118,7 @@ func (c *Handler) OnError(socket *gws.Conn, err error) { c.DeleteSession(socket)
func (c *Handler) OnClose(socket *gws.Conn, code uint16, reason []byte) { c.DeleteSession(socket) }

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

Expand All @@ -138,7 +142,7 @@ import (

func main() {
upgrader := gws.NewUpgrader(new(gws.BuiltinEventHandler), &gws.ServerOption{
CheckOrigin: func(r *http.Request, session gws.SessionStorage) bool {
Authorize: func(r *http.Request, session gws.SessionStorage) bool {
session.Store("username", r.URL.Query().Get("username"))
return true
},
Expand Down Expand Up @@ -167,13 +171,14 @@ func main() {
package main

import (
"github.com/lxzan/gws"
"log"
"net"

"github.com/lxzan/gws"
)

func main() {
listener, err := net.Listen("unix", "/run/gws.sock")
listener, err := net.Listen("unix", "/tmp/gws.sock")
if err != nil {
log.Println(err.Error())
return
Expand All @@ -191,15 +196,21 @@ func main() {
package main

import (
"fmt"
"github.com/lxzan/gws"
"log"
"net"

"github.com/lxzan/gws"
)

func main() {
socket, _, err := gws.NewClient(new(gws.BuiltinEventHandler), &gws.ClientOption{
Addr: "unix://localhost/run/gws.sock",
})
conn, err := net.Dial("unix", "/tmp/gws.sock")
if err != nil {
log.Println(err.Error())
return
}

option := gws.ClientOption{}
socket, _, err := gws.NewClientFromConn(new(gws.BuiltinEventHandler), &option, conn)
if err != nil {
log.Println(err.Error())
return
Expand All @@ -218,26 +229,6 @@ func Broadcast(conns []*gws.Conn, opcode gws.Opcode, payload []byte) {
}
```

#### Write JSON

```go
socket.WriteAny(gws.JsonCodec, gws.OpcodeText, data)
```

#### Customize Codec

```go
import json "github.com/json-iterator/go"

var JsonCodec = new(jsonCodec)

type jsonCodec struct{}

func (c jsonCodec) NewEncoder(writer io.Writer) Encoder {
return json.NewEncoder(writer)
}
```

### Autobahn Test

```bash
Expand Down
1 change: 1 addition & 0 deletions autobahn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
report/
15 changes: 15 additions & 0 deletions autobahn/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
test-server:
docker run -it --rm \
-v ${PWD}/config:/config \
-v ${PWD}/reports:/reports \
crossbario/autobahn-testsuite \
wstest -m fuzzingclient -s /config/fuzzingclient.json

test-client:
docker run -it --rm \
-v ${PWD}/config:/config \
-v ${PWD}/reports:/reports \
-p 9001:9001 \
-p 9002:8080 \
crossbario/autobahn-testsuite \
wstest -m fuzzingserver -s /config/fuzzingserver.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ func updateReports() {
log.Println(err.Error())
return
}
go socket.Listen()
go socket.ReadLoop()
<-handler.onexit
}
26 changes: 26 additions & 0 deletions autobahn/config/fuzzingclient.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"outdir": "./report/",
"servers": [
{
"agent": "non-tls",
"url": "ws://localhost:3000/connect",
"options": {
"version": 18
}
},
{
"agent": "tls",
"url": "wss://localhost:3001/connect",
"options": {
"version": 18
}
}
],
"cases": [
"*"
],
"exclude-cases": [
"1[1-4].*"
],
"exclude-agent-cases": {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"url": "ws://127.0.0.1:9001",
"outdir": "./reports/clients",
"cases": ["*"],
"outdir": "./report/clients",
"cases": [
"*"
],
"exclude-cases": [],
"exclude-agent-cases": {}
}
Loading

0 comments on commit f1f87a1

Please sign in to comment.