x.websocket: websocket server fix and bring back server autobahn (#8291)

pull/8298/head
Tomas Hellström 2021-01-23 16:56:38 +01:00 committed by GitHub
parent 4065a0327a
commit 39e5f6e9df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 713 additions and 694 deletions

View File

@ -25,23 +25,23 @@ jobs:
- name: v test-fmt
run: ./v -silent test-fmt
# v-fmt:
# runs-on: ubuntu-20.04
# timeout-minutes: 30
# steps:
# - uses: actions/checkout@v2
# - name: getting all branch metainfo from github
# run: |
# git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
# echo "Changed files compared to origin/master are:" && git diff --name-status origin/master HEAD -- '*.v'
# - name: Build v (there is no need for dependencies for fmt)
# run: make -j4
# - name: Build a production cmd/tools/vfmt
# run: ./v -prod -d vfmt cmd/tools/vfmt.v
# - name: Run v fmt -diff on only the changed files. Does NOT fail for now.
# run: git diff --name-status origin/master HEAD -- '*.v' |grep -v '^D'|rev|cut -f1|rev| xargs ./v fmt -noerror -diff
# - name: Run v test-fmt
# run: echo "TODO" #./v test-fmt
# v-fmt:
# runs-on: ubuntu-20.04
# timeout-minutes: 30
# steps:
# - uses: actions/checkout@v2
# - name: getting all branch metainfo from github
# run: |
# git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
# echo "Changed files compared to origin/master are:" && git diff --name-status origin/master HEAD -- '*.v'
# - name: Build v (there is no need for dependencies for fmt)
# run: make -j4
# - name: Build a production cmd/tools/vfmt
# run: ./v -prod -d vfmt cmd/tools/vfmt.v
# - name: Run v fmt -diff on only the changed files. Does NOT fail for now.
# run: git diff --name-status origin/master HEAD -- '*.v' |grep -v '^D'|rev|cut -f1|rev| xargs ./v fmt -noerror -diff
# - name: Run v test-fmt
# run: echo "TODO" #./v test-fmt
performance-regressions:
runs-on: ubuntu-20.04
@ -94,7 +94,7 @@ jobs:
run: |
thirdparty/tcc/tcc.exe -version
./v -cg -o v cmd/v # Make sure vtcc can build itself twice
# ./v -silent test-all
# ./v -silent test-all
- name: v self compilation
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
- name: v doctor
@ -127,7 +127,6 @@ jobs:
cd tutorials/code/blog
../../../v .
# Alpine docker pre-built container
alpine-docker-musl-gcc:
name: alpine-musl
@ -188,18 +187,18 @@ jobs:
run: ./v -o v2 -usecache cmd/v
- name: Test symlink
run: ./v symlink
# - name: Set up pg database
# run: |
# pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# psql -d postgres -c 'select rolname from pg_roles'
# psql -d postgres -c 'create database customerdb;'
# psql -d customerdb -f examples/database/pg/mydb.sql
# - name: Test v->c
# run: ./v -silent test-all
# - name: Test v binaries
# run: ./v build-vbinaries
## - name: Test v->js
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
# - name: Set up pg database
# run: |
# pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# psql -d postgres -c 'select rolname from pg_roles'
# psql -d postgres -c 'create database customerdb;'
# psql -d customerdb -f examples/database/pg/mydb.sql
# - name: Test v->c
# run: ./v -silent test-all
# - name: Test v binaries
# run: ./v build-vbinaries
## - name: Test v->js
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
- name: Verify `v test` works
run: |
./v cmd/tools/test_if_v_test_system_works.v
@ -222,8 +221,8 @@ jobs:
run: |
./v -os windows cmd/v
./v -os windows examples/2048/2048.v
# - name: Test vsh
# run: ./v examples/v_script.vsh
# - name: Test vsh
# run: ./v examples/v_script.vsh
- name: Test ved
run: |
git clone --depth 1 https://github.com/vlang/ved
@ -263,18 +262,18 @@ jobs:
./v -o v3 cmd/v -cflags "-fsanitize=undefined -fno-sanitize=alignment"
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v2 -o v.c cmd/v
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v3 -o v.c cmd/v
# - name: Test V
# run: ./v -silent test-all
# - name: Test v binaries
# run: ./v build-vbinaries
## - name: Test v->js
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
# - name: Build Vorum
# run: git clone --depth 1 https://github.com/vlang/vorum && cd vorum && ../v . && cd ..
# - name: Build vpm
# run: git clone --depth 1 https://github.com/vlang/vpm && cd vpm && ../v . && cd ..
# - name: Freestanding
# run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v
# - name: Test V
# run: ./v -silent test-all
# - name: Test v binaries
# run: ./v build-vbinaries
## - name: Test v->js
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
# - name: Build Vorum
# run: git clone --depth 1 https://github.com/vlang/vorum && cd vorum && ../v . && cd ..
# - name: Build vpm
# run: git clone --depth 1 https://github.com/vlang/vpm && cd vpm && ../v . && cd ..
# - name: Freestanding
# run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v
- name: v self compilation
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
- name: -usecache
@ -322,15 +321,15 @@ jobs:
../../vprod -backend x64 -o 1m 1m.v
echo "Running it..."
ls
# - name: SDL examples
# run: git clone --depth 1 https://github.com/vlang/sdl && cd sdl
# - name: SDL examples
# run: git clone --depth 1 https://github.com/vlang/sdl && cd sdl
# ./1m
# ./1m
#run: echo "TODO" #cd examples/x64 && ../../v -x64 hello_world.v && ./hello_world
# - name: Coveralls GitHub Action
# uses: coverallsapp/github-action@v1.0.1
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# - name: Coveralls GitHub Action
# uses: coverallsapp/github-action@v1.0.1
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
ubuntu-clang:
runs-on: ubuntu-20.04
@ -477,18 +476,17 @@ jobs:
- name: Self tests (-fsanitize=memory)
run: ./v -cflags -fsanitize=memory test-self
# ubuntu-autofree-selfcompile:
# runs-on: ubuntu-20.04
# timeout-minutes: 30
# env:
# VFLAGS: -cc gcc
# steps:
# - uses: actions/checkout@v2
# - name: Build V
# run: make -j4
# - name: V self compilation with -autofree
# run: ./v -o v2 -autofree cmd/v && ./v2 -o v3 -autofree cmd/v && ./v3 -o v4 -autofree cmd/v
# ubuntu-autofree-selfcompile:
# runs-on: ubuntu-20.04
# timeout-minutes: 30
# env:
# VFLAGS: -cc gcc
# steps:
# - uses: actions/checkout@v2
# - name: Build V
# run: make -j4
# - name: V self compilation with -autofree
# run: ./v -o v2 -autofree cmd/v && ./v2 -o v3 -autofree cmd/v && ./v3 -o v4 -autofree cmd/v
# Ubuntu docker pre-built container
ubuntu-musl:
@ -518,41 +516,41 @@ jobs:
run: |
./v -silent test-self
# ubuntu-musl:
# runs-on: ubuntu-20.04
# timeout-minutes: 30
# env:
# VFLAGS: -cc musl-gcc
# V_CI_MUSL: 1
# steps:
# - uses: actions/checkout@v2
# - uses: actions/setup-node@v1
# with:
# node-version: 12.x
# - name: Install dependencies
# run: |
# sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list;
# sudo apt-get update;
# sudo apt-get install --quiet -y musl musl-tools libssl-dev sqlite3 libsqlite3-dev valgrind
# sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev
# - name: Build v
# run: echo $VFLAGS && make -j4 && ./v -cg -o v cmd/v
# # - name: Test v binaries
# # run: ./v build-vbinaries
# ## - name: Test v->js
# ## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
# - name: quick debug
# run: ./v -stats vlib/strconv/format_test.v
# - name: Self tests
# run: ./v -silent test-self
# ubuntu-musl:
# runs-on: ubuntu-20.04
# timeout-minutes: 30
# env:
# VFLAGS: -cc musl-gcc
# V_CI_MUSL: 1
# steps:
# - uses: actions/checkout@v2
# - uses: actions/setup-node@v1
# with:
# node-version: 12.x
# - name: Install dependencies
# run: |
# sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list;
# sudo apt-get update;
# sudo apt-get install --quiet -y musl musl-tools libssl-dev sqlite3 libsqlite3-dev valgrind
# sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev
# - name: Build v
# run: echo $VFLAGS && make -j4 && ./v -cg -o v cmd/v
# # - name: Test v binaries
# # run: ./v build-vbinaries
# ## - name: Test v->js
# ## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
# - name: quick debug
# run: ./v -stats vlib/strconv/format_test.v
# - name: Self tests
# run: ./v -silent test-self
ubuntu-llvm-mingw:
runs-on: ubuntu-20.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
# - name: Cross-compile V
# run: docker build . -f Dockerfile.cross
# - name: Cross-compile V
# run: docker build . -f Dockerfile.cross
windows-gcc:
runs-on: windows-2019
@ -582,9 +580,9 @@ jobs:
- name: Self tests
run: |
.\v.exe -silent test-self
# - name: Test
# run: |
# .\v.exe -silent test-all
# - name: Test
# run: |
# .\v.exe -silent test-all
## v.js dosent work on windows
#.\v.exe -o hi.js examples/hello_v_js.v
#node hi.js
@ -627,14 +625,14 @@ jobs:
./v -silent test-self
- name: Build examples
run: ./v build-examples
# - name: Test
# run: |
# .\v.exe -silent test-all
# ## v.js dosent work on windows
# - name: Test
# run: |
# .\v.exe -silent test-all
# ## v.js dosent work on windows
#.\v.exe -o hi.js examples/hello_v_js.v
#node hi.js
# - name: Test v binaries
# run: ./v build-vbinaries
# - name: Test v binaries
# run: ./v build-vbinaries
windows-tcc:
runs-on: windows-2019
@ -660,17 +658,16 @@ jobs:
- name: Self tests
run: |
.\v.exe -silent test-self
# - name: Test
# run: |
# .\v.exe -silent test-all
# - name: Test
# run: |
# .\v.exe -silent test-all
## v.js dosent work on windows
#.\v.exe -o hi.js examples/hello_v_js.v
#node hi.js
# - name: Test v binaries
# run: ./v build-vbinaries
# - name: v2 self compilation
# run: .\v.exe -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v
# - name: Test v binaries
# run: ./v build-vbinaries
# - name: v2 self compilation
# run: .\v.exe -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v
compilable-v-c-and-v-win-c:
runs-on: ubuntu-20.04
@ -727,8 +724,8 @@ jobs:
run: g++-9 --version
- name: V self compilation with g++
run: ./v -cc g++-9 -o v2 cmd/v && ./v2 -cc g++-9 -o v3 cmd/v
## - name: Running tests with g++
## run: ./v -cc g++-9 -silent test-self
## - name: Running tests with g++
## run: ./v -cc g++-9 -silent test-self
install-modules:
runs-on: ubuntu-20.04
@ -781,8 +778,8 @@ jobs:
run: docker exec autobahn_client "/src/v" "/src/vlib/x/websocket/tests/autobahn/autobahn_client_wss.v"
- name: Run client wss test
run: docker exec autobahn_client "/src/vlib/x/websocket/tests/autobahn/autobahn_client_wss"
# - name: Run server test
# run: docker exec autobahn_server "wstest" "-m" "fuzzingclient" "-s" "/config/fuzzingclient.json"
- name: Run server test
run: docker exec autobahn_server "wstest" "-m" "fuzzingclient" "-s" "/config/fuzzingclient.json"
- name: Copy reports
run: docker cp autobahn_server:/reports ${{github.workspace}}/reports
- name: Copy reports wss
@ -802,11 +799,11 @@ jobs:
with:
name: client
path: ${{github.workspace}}/reports/clients/index.html
# - name: Publish report server
# uses: actions/upload-artifact@v2
# with:
# name: server
# path: ${{github.workspace}}/reports/servers/index.html
- name: Publish report server
uses: actions/upload-artifact@v2
with:
name: server
path: ${{github.workspace}}/reports/servers/index.html
- name: Publish all reports WSS
uses: actions/upload-artifact@v2
with:

View File

@ -19,17 +19,17 @@ with open("/reports/clients/index.json") as f:
nr_of_client_tests = nr_of_client_tests + 1
# with open("/reports/servers/index.json") as f:
# data = json.load(f)
with open("/reports/servers/index.json") as f:
data = json.load(f)
# for i in data["AutobahnServer"]:
# if (
# data["AutobahnServer"][i]["behavior"] == "FAILED"
# or data["AutobahnServer"][i]["behaviorClose"] == "FAILED"
# ):
# nr_of_server_errs = nr_of_server_errs + 1
for i in data["AutobahnServer"]:
if (
data["AutobahnServer"][i]["behavior"] == "FAILED"
or data["AutobahnServer"][i]["behaviorClose"] == "FAILED"
):
nr_of_server_errs = nr_of_server_errs + 1
# nr_of_server_tests = nr_of_server_tests + 1
nr_of_server_tests = nr_of_server_tests + 1
if nr_of_client_errs > 0 or nr_of_server_errs > 0:
print(

View File

@ -73,8 +73,8 @@ fn (mut s Server) handle_ping() {
mut clients_to_remove := []string{}
for s.state == .open {
time.sleep(s.ping_interval)
for _, cli in s.clients {
mut c := cli
for i, _ in s.clients {
mut c := s.clients[i]
if c.client.state == .open {
c.client.ping() or {
s.logger.debug('server-> error sending ping to client')

View File

@ -1,6 +1,12 @@
import x.websocket
import time
struct WebsocketTestResults {
pub mut:
nr_messages int
nr_pong_received int
}
// tests with internal ws servers
fn test_ws() {
go start_server()
@ -11,7 +17,8 @@ fn test_ws() {
fn start_server() ? {
mut s := websocket.new_server(30000, '')
// make that in execution test time give time to execute at least one time
s.ping_interval = 100
s.ping_interval = 1
s.on_connect(fn (mut s websocket.ServerClient) ?bool {
// here you can look att the client info and accept or not accept
// just returning a true/false
@ -22,8 +29,12 @@ fn start_server() ? {
return true
}) ?
s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
ws.write(msg.payload, msg.opcode) or { panic(err) }
match msg.opcode {
.pong { ws.write_str('pong') }
else { ws.write(msg.payload, msg.opcode) or { panic(err) } }
}
})
s.on_close(fn (mut ws websocket.Client, code int, reason string) ? {
// not used
})
@ -33,10 +44,11 @@ fn start_server() ? {
// ws_test tests connect to the websocket server from websocket client
fn ws_test(uri string) ? {
eprintln('connecting to $uri ...')
mut test_results := WebsocketTestResults{}
mut ws := websocket.new_client(uri) ?
ws.on_open(fn (mut ws websocket.Client) ? {
println('open!')
ws.pong()
ws.pong() ?
assert true
})
ws.on_error(fn (mut ws websocket.Client, err string) ? {
@ -44,19 +56,26 @@ fn ws_test(uri string) ? {
// this can be thrown by internet connection problems
assert false
})
ws.on_close(fn (mut ws websocket.Client, code int, reason string) ? {
println('closed')
})
ws.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
ws.on_message_ref(fn (mut ws websocket.Client, msg &websocket.Message, mut res WebsocketTestResults) ? {
println('client got type: $msg.opcode payload:\n$msg.payload')
if msg.opcode == .text_frame {
smessage := msg.payload.bytestr()
println('Message: $smessage')
assert smessage == 'a'
match smessage {
'pong' {
res.nr_pong_received++
}
'a' {
res.nr_messages++
}
else {
assert false
}
}
} else {
println('Binary message: $msg')
}
})
}, test_results)
ws.connect() or { panic('fail to connect') }
go ws.listen()
text := ['a'].repeat(2)
@ -66,5 +85,8 @@ fn ws_test(uri string) ? {
time.sleep_ms(100)
}
// sleep to give time to recieve response before asserts
time.sleep_ms(500)
time.sleep_ms(1500)
// We expect at least 2 pongs, one sent directly and one indirectly
assert test_results.nr_pong_received >= 2
assert test_results.nr_messages == 2
}