x.websocket: websocket server fix and bring back server autobahn (#8291)
parent
4065a0327a
commit
39e5f6e9df
|
@ -25,23 +25,23 @@ jobs:
|
||||||
- name: v test-fmt
|
- name: v test-fmt
|
||||||
run: ./v -silent test-fmt
|
run: ./v -silent test-fmt
|
||||||
|
|
||||||
# v-fmt:
|
# v-fmt:
|
||||||
# runs-on: ubuntu-20.04
|
# runs-on: ubuntu-20.04
|
||||||
# timeout-minutes: 30
|
# timeout-minutes: 30
|
||||||
# steps:
|
# steps:
|
||||||
# - uses: actions/checkout@v2
|
# - uses: actions/checkout@v2
|
||||||
# - name: getting all branch metainfo from github
|
# - name: getting all branch metainfo from github
|
||||||
# run: |
|
# run: |
|
||||||
# git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
|
# 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'
|
# 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)
|
# - name: Build v (there is no need for dependencies for fmt)
|
||||||
# run: make -j4
|
# run: make -j4
|
||||||
# - name: Build a production cmd/tools/vfmt
|
# - name: Build a production cmd/tools/vfmt
|
||||||
# run: ./v -prod -d vfmt cmd/tools/vfmt.v
|
# run: ./v -prod -d vfmt cmd/tools/vfmt.v
|
||||||
# - name: Run v fmt -diff on only the changed files. Does NOT fail for now.
|
# - 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
|
# 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
|
# - name: Run v test-fmt
|
||||||
# run: echo "TODO" #./v test-fmt
|
# run: echo "TODO" #./v test-fmt
|
||||||
|
|
||||||
performance-regressions:
|
performance-regressions:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
@ -94,7 +94,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
thirdparty/tcc/tcc.exe -version
|
thirdparty/tcc/tcc.exe -version
|
||||||
./v -cg -o v cmd/v # Make sure vtcc can build itself twice
|
./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
|
- name: v self compilation
|
||||||
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
|
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
|
||||||
- name: v doctor
|
- name: v doctor
|
||||||
|
@ -127,7 +127,6 @@ jobs:
|
||||||
cd tutorials/code/blog
|
cd tutorials/code/blog
|
||||||
../../../v .
|
../../../v .
|
||||||
|
|
||||||
|
|
||||||
# Alpine docker pre-built container
|
# Alpine docker pre-built container
|
||||||
alpine-docker-musl-gcc:
|
alpine-docker-musl-gcc:
|
||||||
name: alpine-musl
|
name: alpine-musl
|
||||||
|
@ -188,18 +187,18 @@ jobs:
|
||||||
run: ./v -o v2 -usecache cmd/v
|
run: ./v -o v2 -usecache cmd/v
|
||||||
- name: Test symlink
|
- name: Test symlink
|
||||||
run: ./v symlink
|
run: ./v symlink
|
||||||
# - name: Set up pg database
|
# - name: Set up pg database
|
||||||
# run: |
|
# run: |
|
||||||
# pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
|
# 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 'select rolname from pg_roles'
|
||||||
# psql -d postgres -c 'create database customerdb;'
|
# psql -d postgres -c 'create database customerdb;'
|
||||||
# psql -d customerdb -f examples/database/pg/mydb.sql
|
# psql -d customerdb -f examples/database/pg/mydb.sql
|
||||||
# - name: Test v->c
|
# - name: Test v->c
|
||||||
# run: ./v -silent test-all
|
# run: ./v -silent test-all
|
||||||
# - name: Test v binaries
|
# - name: Test v binaries
|
||||||
# run: ./v build-vbinaries
|
# run: ./v build-vbinaries
|
||||||
## - name: Test v->js
|
## - name: Test v->js
|
||||||
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
|
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
|
||||||
- name: Verify `v test` works
|
- name: Verify `v test` works
|
||||||
run: |
|
run: |
|
||||||
./v cmd/tools/test_if_v_test_system_works.v
|
./v cmd/tools/test_if_v_test_system_works.v
|
||||||
|
@ -222,8 +221,8 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
./v -os windows cmd/v
|
./v -os windows cmd/v
|
||||||
./v -os windows examples/2048/2048.v
|
./v -os windows examples/2048/2048.v
|
||||||
# - name: Test vsh
|
# - name: Test vsh
|
||||||
# run: ./v examples/v_script.vsh
|
# run: ./v examples/v_script.vsh
|
||||||
- name: Test ved
|
- name: Test ved
|
||||||
run: |
|
run: |
|
||||||
git clone --depth 1 https://github.com/vlang/ved
|
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"
|
./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 ./v2 -o v.c cmd/v
|
||||||
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v3 -o v.c cmd/v
|
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./v3 -o v.c cmd/v
|
||||||
# - name: Test V
|
# - name: Test V
|
||||||
# run: ./v -silent test-all
|
# run: ./v -silent test-all
|
||||||
# - name: Test v binaries
|
# - name: Test v binaries
|
||||||
# run: ./v build-vbinaries
|
# run: ./v build-vbinaries
|
||||||
## - name: Test v->js
|
## - name: Test v->js
|
||||||
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
|
## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
|
||||||
# - name: Build Vorum
|
# - name: Build Vorum
|
||||||
# run: git clone --depth 1 https://github.com/vlang/vorum && cd vorum && ../v . && cd ..
|
# run: git clone --depth 1 https://github.com/vlang/vorum && cd vorum && ../v . && cd ..
|
||||||
# - name: Build vpm
|
# - name: Build vpm
|
||||||
# run: git clone --depth 1 https://github.com/vlang/vpm && cd vpm && ../v . && cd ..
|
# run: git clone --depth 1 https://github.com/vlang/vpm && cd vpm && ../v . && cd ..
|
||||||
# - name: Freestanding
|
# - name: Freestanding
|
||||||
# run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v
|
# run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v
|
||||||
- name: v self compilation
|
- name: v self compilation
|
||||||
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
|
run: ./v -o v2 cmd/v && ./v2 -o v3 cmd/v && ./v3 -o v4 cmd/v
|
||||||
- name: -usecache
|
- name: -usecache
|
||||||
|
@ -322,15 +321,15 @@ jobs:
|
||||||
../../vprod -backend x64 -o 1m 1m.v
|
../../vprod -backend x64 -o 1m 1m.v
|
||||||
echo "Running it..."
|
echo "Running it..."
|
||||||
ls
|
ls
|
||||||
# - name: SDL examples
|
# - name: SDL examples
|
||||||
# run: git clone --depth 1 https://github.com/vlang/sdl && cd sdl
|
# 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
|
#run: echo "TODO" #cd examples/x64 && ../../v -x64 hello_world.v && ./hello_world
|
||||||
# - name: Coveralls GitHub Action
|
# - name: Coveralls GitHub Action
|
||||||
# uses: coverallsapp/github-action@v1.0.1
|
# uses: coverallsapp/github-action@v1.0.1
|
||||||
# with:
|
# with:
|
||||||
# github-token: ${{ secrets.GITHUB_TOKEN }}
|
# github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
ubuntu-clang:
|
ubuntu-clang:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
@ -477,18 +476,17 @@ jobs:
|
||||||
- name: Self tests (-fsanitize=memory)
|
- name: Self tests (-fsanitize=memory)
|
||||||
run: ./v -cflags -fsanitize=memory test-self
|
run: ./v -cflags -fsanitize=memory test-self
|
||||||
|
|
||||||
# ubuntu-autofree-selfcompile:
|
# ubuntu-autofree-selfcompile:
|
||||||
# runs-on: ubuntu-20.04
|
# runs-on: ubuntu-20.04
|
||||||
# timeout-minutes: 30
|
# timeout-minutes: 30
|
||||||
# env:
|
# env:
|
||||||
# VFLAGS: -cc gcc
|
# VFLAGS: -cc gcc
|
||||||
# steps:
|
# steps:
|
||||||
# - uses: actions/checkout@v2
|
# - uses: actions/checkout@v2
|
||||||
# - name: Build V
|
# - name: Build V
|
||||||
# run: make -j4
|
# run: make -j4
|
||||||
# - name: V self compilation with -autofree
|
# - 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
|
# 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 docker pre-built container
|
||||||
ubuntu-musl:
|
ubuntu-musl:
|
||||||
|
@ -518,41 +516,41 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
./v -silent test-self
|
./v -silent test-self
|
||||||
|
|
||||||
# ubuntu-musl:
|
# ubuntu-musl:
|
||||||
# runs-on: ubuntu-20.04
|
# runs-on: ubuntu-20.04
|
||||||
# timeout-minutes: 30
|
# timeout-minutes: 30
|
||||||
# env:
|
# env:
|
||||||
# VFLAGS: -cc musl-gcc
|
# VFLAGS: -cc musl-gcc
|
||||||
# V_CI_MUSL: 1
|
# V_CI_MUSL: 1
|
||||||
# steps:
|
# steps:
|
||||||
# - uses: actions/checkout@v2
|
# - uses: actions/checkout@v2
|
||||||
# - uses: actions/setup-node@v1
|
# - uses: actions/setup-node@v1
|
||||||
# with:
|
# with:
|
||||||
# node-version: 12.x
|
# node-version: 12.x
|
||||||
# - name: Install dependencies
|
# - name: Install dependencies
|
||||||
# run: |
|
# run: |
|
||||||
# sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list;
|
# 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 update;
|
||||||
# sudo apt-get install --quiet -y musl musl-tools libssl-dev sqlite3 libsqlite3-dev valgrind
|
# 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
|
# sudo apt-get install --quiet -y libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev
|
||||||
# - name: Build v
|
# - name: Build v
|
||||||
# run: echo $VFLAGS && make -j4 && ./v -cg -o v cmd/v
|
# run: echo $VFLAGS && make -j4 && ./v -cg -o v cmd/v
|
||||||
# # - name: Test v binaries
|
# # - name: Test v binaries
|
||||||
# # run: ./v build-vbinaries
|
# # run: ./v build-vbinaries
|
||||||
# ## - name: Test v->js
|
# ## - name: Test v->js
|
||||||
# ## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
|
# ## run: ./v -o hi.js examples/hello_v_js.v && node hi.js
|
||||||
# - name: quick debug
|
# - name: quick debug
|
||||||
# run: ./v -stats vlib/strconv/format_test.v
|
# run: ./v -stats vlib/strconv/format_test.v
|
||||||
# - name: Self tests
|
# - name: Self tests
|
||||||
# run: ./v -silent test-self
|
# run: ./v -silent test-self
|
||||||
|
|
||||||
ubuntu-llvm-mingw:
|
ubuntu-llvm-mingw:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
# - name: Cross-compile V
|
# - name: Cross-compile V
|
||||||
# run: docker build . -f Dockerfile.cross
|
# run: docker build . -f Dockerfile.cross
|
||||||
|
|
||||||
windows-gcc:
|
windows-gcc:
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
|
@ -582,9 +580,9 @@ jobs:
|
||||||
- name: Self tests
|
- name: Self tests
|
||||||
run: |
|
run: |
|
||||||
.\v.exe -silent test-self
|
.\v.exe -silent test-self
|
||||||
# - name: Test
|
# - name: Test
|
||||||
# run: |
|
# run: |
|
||||||
# .\v.exe -silent test-all
|
# .\v.exe -silent test-all
|
||||||
## v.js dosent work on windows
|
## v.js dosent work on windows
|
||||||
#.\v.exe -o hi.js examples/hello_v_js.v
|
#.\v.exe -o hi.js examples/hello_v_js.v
|
||||||
#node hi.js
|
#node hi.js
|
||||||
|
@ -627,14 +625,14 @@ jobs:
|
||||||
./v -silent test-self
|
./v -silent test-self
|
||||||
- name: Build examples
|
- name: Build examples
|
||||||
run: ./v build-examples
|
run: ./v build-examples
|
||||||
# - name: Test
|
# - name: Test
|
||||||
# run: |
|
# run: |
|
||||||
# .\v.exe -silent test-all
|
# .\v.exe -silent test-all
|
||||||
# ## v.js dosent work on windows
|
# ## v.js dosent work on windows
|
||||||
#.\v.exe -o hi.js examples/hello_v_js.v
|
#.\v.exe -o hi.js examples/hello_v_js.v
|
||||||
#node hi.js
|
#node hi.js
|
||||||
# - name: Test v binaries
|
# - name: Test v binaries
|
||||||
# run: ./v build-vbinaries
|
# run: ./v build-vbinaries
|
||||||
|
|
||||||
windows-tcc:
|
windows-tcc:
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
|
@ -660,17 +658,16 @@ jobs:
|
||||||
- name: Self tests
|
- name: Self tests
|
||||||
run: |
|
run: |
|
||||||
.\v.exe -silent test-self
|
.\v.exe -silent test-self
|
||||||
# - name: Test
|
# - name: Test
|
||||||
# run: |
|
# run: |
|
||||||
# .\v.exe -silent test-all
|
# .\v.exe -silent test-all
|
||||||
## v.js dosent work on windows
|
## v.js dosent work on windows
|
||||||
#.\v.exe -o hi.js examples/hello_v_js.v
|
#.\v.exe -o hi.js examples/hello_v_js.v
|
||||||
#node hi.js
|
#node hi.js
|
||||||
# - name: Test v binaries
|
# - name: Test v binaries
|
||||||
# run: ./v build-vbinaries
|
# run: ./v build-vbinaries
|
||||||
# - name: v2 self compilation
|
# - name: v2 self compilation
|
||||||
# run: .\v.exe -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v
|
# run: .\v.exe -o v2.exe cmd/v && .\v2.exe -o v3.exe cmd/v
|
||||||
|
|
||||||
|
|
||||||
compilable-v-c-and-v-win-c:
|
compilable-v-c-and-v-win-c:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
@ -727,8 +724,8 @@ jobs:
|
||||||
run: g++-9 --version
|
run: g++-9 --version
|
||||||
- name: V self compilation with g++
|
- name: V self compilation with g++
|
||||||
run: ./v -cc g++-9 -o v2 cmd/v && ./v2 -cc g++-9 -o v3 cmd/v
|
run: ./v -cc g++-9 -o v2 cmd/v && ./v2 -cc g++-9 -o v3 cmd/v
|
||||||
## - name: Running tests with g++
|
## - name: Running tests with g++
|
||||||
## run: ./v -cc g++-9 -silent test-self
|
## run: ./v -cc g++-9 -silent test-self
|
||||||
|
|
||||||
install-modules:
|
install-modules:
|
||||||
runs-on: ubuntu-20.04
|
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"
|
run: docker exec autobahn_client "/src/v" "/src/vlib/x/websocket/tests/autobahn/autobahn_client_wss.v"
|
||||||
- name: Run client wss test
|
- name: Run client wss test
|
||||||
run: docker exec autobahn_client "/src/vlib/x/websocket/tests/autobahn/autobahn_client_wss"
|
run: docker exec autobahn_client "/src/vlib/x/websocket/tests/autobahn/autobahn_client_wss"
|
||||||
# - name: Run server test
|
- name: Run server test
|
||||||
# run: docker exec autobahn_server "wstest" "-m" "fuzzingclient" "-s" "/config/fuzzingclient.json"
|
run: docker exec autobahn_server "wstest" "-m" "fuzzingclient" "-s" "/config/fuzzingclient.json"
|
||||||
- name: Copy reports
|
- name: Copy reports
|
||||||
run: docker cp autobahn_server:/reports ${{github.workspace}}/reports
|
run: docker cp autobahn_server:/reports ${{github.workspace}}/reports
|
||||||
- name: Copy reports wss
|
- name: Copy reports wss
|
||||||
|
@ -802,11 +799,11 @@ jobs:
|
||||||
with:
|
with:
|
||||||
name: client
|
name: client
|
||||||
path: ${{github.workspace}}/reports/clients/index.html
|
path: ${{github.workspace}}/reports/clients/index.html
|
||||||
# - name: Publish report server
|
- name: Publish report server
|
||||||
# uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
# with:
|
with:
|
||||||
# name: server
|
name: server
|
||||||
# path: ${{github.workspace}}/reports/servers/index.html
|
path: ${{github.workspace}}/reports/servers/index.html
|
||||||
- name: Publish all reports WSS
|
- name: Publish all reports WSS
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -19,17 +19,17 @@ with open("/reports/clients/index.json") as f:
|
||||||
|
|
||||||
nr_of_client_tests = nr_of_client_tests + 1
|
nr_of_client_tests = nr_of_client_tests + 1
|
||||||
|
|
||||||
# with open("/reports/servers/index.json") as f:
|
with open("/reports/servers/index.json") as f:
|
||||||
# data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
# for i in data["AutobahnServer"]:
|
for i in data["AutobahnServer"]:
|
||||||
# if (
|
if (
|
||||||
# data["AutobahnServer"][i]["behavior"] == "FAILED"
|
data["AutobahnServer"][i]["behavior"] == "FAILED"
|
||||||
# or data["AutobahnServer"][i]["behaviorClose"] == "FAILED"
|
or data["AutobahnServer"][i]["behaviorClose"] == "FAILED"
|
||||||
# ):
|
):
|
||||||
# nr_of_server_errs = nr_of_server_errs + 1
|
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:
|
if nr_of_client_errs > 0 or nr_of_server_errs > 0:
|
||||||
print(
|
print(
|
||||||
|
|
|
@ -73,8 +73,8 @@ fn (mut s Server) handle_ping() {
|
||||||
mut clients_to_remove := []string{}
|
mut clients_to_remove := []string{}
|
||||||
for s.state == .open {
|
for s.state == .open {
|
||||||
time.sleep(s.ping_interval)
|
time.sleep(s.ping_interval)
|
||||||
for _, cli in s.clients {
|
for i, _ in s.clients {
|
||||||
mut c := cli
|
mut c := s.clients[i]
|
||||||
if c.client.state == .open {
|
if c.client.state == .open {
|
||||||
c.client.ping() or {
|
c.client.ping() or {
|
||||||
s.logger.debug('server-> error sending ping to client')
|
s.logger.debug('server-> error sending ping to client')
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
import x.websocket
|
import x.websocket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
struct WebsocketTestResults {
|
||||||
|
pub mut:
|
||||||
|
nr_messages int
|
||||||
|
nr_pong_received int
|
||||||
|
}
|
||||||
|
|
||||||
// tests with internal ws servers
|
// tests with internal ws servers
|
||||||
fn test_ws() {
|
fn test_ws() {
|
||||||
go start_server()
|
go start_server()
|
||||||
|
@ -11,7 +17,8 @@ fn test_ws() {
|
||||||
fn start_server() ? {
|
fn start_server() ? {
|
||||||
mut s := websocket.new_server(30000, '')
|
mut s := websocket.new_server(30000, '')
|
||||||
// make that in execution test time give time to execute at least one time
|
// 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 {
|
s.on_connect(fn (mut s websocket.ServerClient) ?bool {
|
||||||
// here you can look att the client info and accept or not accept
|
// here you can look att the client info and accept or not accept
|
||||||
// just returning a true/false
|
// just returning a true/false
|
||||||
|
@ -22,8 +29,12 @@ fn start_server() ? {
|
||||||
return true
|
return true
|
||||||
}) ?
|
}) ?
|
||||||
s.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
|
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) ? {
|
s.on_close(fn (mut ws websocket.Client, code int, reason string) ? {
|
||||||
// not used
|
// not used
|
||||||
})
|
})
|
||||||
|
@ -33,10 +44,11 @@ fn start_server() ? {
|
||||||
// ws_test tests connect to the websocket server from websocket client
|
// ws_test tests connect to the websocket server from websocket client
|
||||||
fn ws_test(uri string) ? {
|
fn ws_test(uri string) ? {
|
||||||
eprintln('connecting to $uri ...')
|
eprintln('connecting to $uri ...')
|
||||||
|
|
||||||
|
mut test_results := WebsocketTestResults{}
|
||||||
mut ws := websocket.new_client(uri) ?
|
mut ws := websocket.new_client(uri) ?
|
||||||
ws.on_open(fn (mut ws websocket.Client) ? {
|
ws.on_open(fn (mut ws websocket.Client) ? {
|
||||||
println('open!')
|
ws.pong() ?
|
||||||
ws.pong()
|
|
||||||
assert true
|
assert true
|
||||||
})
|
})
|
||||||
ws.on_error(fn (mut ws websocket.Client, err string) ? {
|
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
|
// this can be thrown by internet connection problems
|
||||||
assert false
|
assert false
|
||||||
})
|
})
|
||||||
ws.on_close(fn (mut ws websocket.Client, code int, reason string) ? {
|
|
||||||
println('closed')
|
ws.on_message_ref(fn (mut ws websocket.Client, msg &websocket.Message, mut res WebsocketTestResults) ? {
|
||||||
})
|
|
||||||
ws.on_message(fn (mut ws websocket.Client, msg &websocket.Message) ? {
|
|
||||||
println('client got type: $msg.opcode payload:\n$msg.payload')
|
println('client got type: $msg.opcode payload:\n$msg.payload')
|
||||||
if msg.opcode == .text_frame {
|
if msg.opcode == .text_frame {
|
||||||
smessage := msg.payload.bytestr()
|
smessage := msg.payload.bytestr()
|
||||||
println('Message: $smessage')
|
match smessage {
|
||||||
assert smessage == 'a'
|
'pong' {
|
||||||
|
res.nr_pong_received++
|
||||||
|
}
|
||||||
|
'a' {
|
||||||
|
res.nr_messages++
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert false
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println('Binary message: $msg')
|
println('Binary message: $msg')
|
||||||
}
|
}
|
||||||
})
|
}, test_results)
|
||||||
ws.connect() or { panic('fail to connect') }
|
ws.connect() or { panic('fail to connect') }
|
||||||
go ws.listen()
|
go ws.listen()
|
||||||
text := ['a'].repeat(2)
|
text := ['a'].repeat(2)
|
||||||
|
@ -66,5 +85,8 @@ fn ws_test(uri string) ? {
|
||||||
time.sleep_ms(100)
|
time.sleep_ms(100)
|
||||||
}
|
}
|
||||||
// sleep to give time to recieve response before asserts
|
// 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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue