mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
x.websockets: new websockets module on top of x.net (#6189)
This commit is contained in:
3
vlib/x/websocket/tests/autobahn/README.md
Normal file
3
vlib/x/websocket/tests/autobahn/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Autobahn tests
|
||||
|
||||
This is the autobahn automatic tests on build. The performance tests are skipped due to timeouts in Github actions.
|
38
vlib/x/websocket/tests/autobahn/autobahn_client.v
Normal file
38
vlib/x/websocket/tests/autobahn/autobahn_client.v
Normal file
@@ -0,0 +1,38 @@
|
||||
// use this test to test the websocket client in the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
||||
fn main() {
|
||||
for i in 1 ..304 {
|
||||
println('\ncase: $i')
|
||||
handle_case(i) or {
|
||||
println('error should be ok: $err')
|
||||
}
|
||||
}
|
||||
// update the reports
|
||||
uri := 'ws://autobahn_server:9001/updateReports?agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://autobahn_server:9001/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.on_message(on_message)
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
||||
// autobahn tests expects to send same message back
|
||||
if msg.opcode == .pong {
|
||||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
}
|
30
vlib/x/websocket/tests/autobahn/autobahn_server.v
Normal file
30
vlib/x/websocket/tests/autobahn/autobahn_server.v
Normal file
@@ -0,0 +1,30 @@
|
||||
// use this to test websocket server to the autobahn test
|
||||
|
||||
module main
|
||||
|
||||
import x.websocket
|
||||
|
||||
fn main() {
|
||||
mut s := websocket.new_server(9002, '/')
|
||||
s.on_message(on_message)
|
||||
s.listen()
|
||||
}
|
||||
|
||||
fn handle_case(case_nr int) ? {
|
||||
uri := 'ws://localhost:9002/runCase?case=$case_nr&agent=v-client'
|
||||
mut ws := websocket.new_client(uri)?
|
||||
ws.on_message(on_message)
|
||||
ws.connect()?
|
||||
ws.listen()?
|
||||
}
|
||||
|
||||
fn on_message(mut ws websocket.Client, msg &websocket.Message)? {
|
||||
// autobahn tests expects to send same message back
|
||||
if msg.opcode == .pong {
|
||||
// We just wanna pass text and binary message back to autobahn
|
||||
return
|
||||
}
|
||||
ws.write(msg.payload, msg.opcode) or {
|
||||
panic(err)
|
||||
}
|
||||
}
|
20
vlib/x/websocket/tests/autobahn/docker-compose.yml
Normal file
20
vlib/x/websocket/tests/autobahn/docker-compose.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
version: '3'
|
||||
services:
|
||||
web:
|
||||
container_name: autobahn_server
|
||||
build: fuzzing_server
|
||||
|
||||
ports:
|
||||
- "9001:9001"
|
||||
- "8080:8080"
|
||||
client:
|
||||
container_name: autobahn_client
|
||||
build:
|
||||
#vlib/x/websocket/tests/autobahn/ws_test/Dockerfile
|
||||
dockerfile: tests/autobahn/ws_test/Dockerfile
|
||||
context: ../../
|
||||
# volumes:
|
||||
# - ../../:/src
|
||||
# redis:
|
||||
# container_name: redis-backend
|
||||
# image: "redis:alpine"
|
@@ -0,0 +1,6 @@
|
||||
FROM crossbario/autobahn-testsuite
|
||||
COPY check_results.py /check_results.py
|
||||
RUN chmod +x /check_results.py
|
||||
|
||||
COPY config/fuzzingserver.json /config/fuzzingserver.json
|
||||
COPY config/fuzzingclient.json /config/fuzzingclient.json
|
@@ -0,0 +1,59 @@
|
||||
import json
|
||||
|
||||
nr_of_client_errs = 0
|
||||
nr_of_client_tests = 0
|
||||
|
||||
nr_of_server_errs = 0
|
||||
nr_of_server_tests = 0
|
||||
|
||||
with open("/reports/clients/index.json") as f:
|
||||
data = json.load(f)
|
||||
|
||||
for i in data["v-client"]:
|
||||
# Count errors
|
||||
if (
|
||||
data["v-client"][i]["behavior"] == "FAILED"
|
||||
or data["v-client"][i]["behaviorClose"] == "FAILED"
|
||||
):
|
||||
nr_of_client_errs = nr_of_client_errs + 1
|
||||
|
||||
nr_of_client_tests = nr_of_client_tests + 1
|
||||
|
||||
with open("/reports/clients/index.json") as f:
|
||||
data = json.load(f)
|
||||
|
||||
for i in data["v-client"]:
|
||||
# Count errors
|
||||
if (
|
||||
data["v-client"][i]["behavior"] == "FAILED"
|
||||
or data["v-client"][i]["behaviorClose"] == "FAILED"
|
||||
):
|
||||
nr_of_client_errs = nr_of_client_errs + 1
|
||||
|
||||
nr_of_client_tests = nr_of_client_tests + 1
|
||||
|
||||
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
|
||||
|
||||
nr_of_server_tests = nr_of_server_tests + 1
|
||||
|
||||
if nr_of_client_errs > 0 or nr_of_server_errs > 0:
|
||||
print(
|
||||
"FAILED AUTOBAHN TESTS, CLIENT ERRORS {0}(of {1}), SERVER ERRORS {2}(of {3})".format(
|
||||
nr_of_client_errs, nr_of_client_tests, nr_of_server_errs, nr_of_server_tests
|
||||
)
|
||||
)
|
||||
exit(1)
|
||||
|
||||
print(
|
||||
"TEST SUCCESS!, CLIENT TESTS({0}), SERVER TESTS ({1})".format(
|
||||
nr_of_client_tests, nr_of_server_tests
|
||||
)
|
||||
)
|
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"options": {
|
||||
"failByDrop": false
|
||||
},
|
||||
"outdir": "./reports/servers",
|
||||
"servers": [
|
||||
{
|
||||
"agent": "AutobahnServer",
|
||||
"url": "ws://autobahn_client:9002"
|
||||
}
|
||||
],
|
||||
"cases": [
|
||||
"*"
|
||||
],
|
||||
"exclude-cases": [
|
||||
"9.*",
|
||||
"11.*",
|
||||
"12.*",
|
||||
"13.*"
|
||||
],
|
||||
"exclude-agent-cases": {}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"url": "ws://127.0.0.1:9001",
|
||||
"outdir": "./reports/clients",
|
||||
"cases": [
|
||||
"*"
|
||||
],
|
||||
"exclude-cases": [
|
||||
"9.*",
|
||||
"11.*",
|
||||
"12.*",
|
||||
"13.*"
|
||||
],
|
||||
"exclude-agent-cases": {}
|
||||
}
|
12
vlib/x/websocket/tests/autobahn/local_run/Dockerfile
Normal file
12
vlib/x/websocket/tests/autobahn/local_run/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
# Use this as docker builder with https://github.com/nektos/act
|
||||
# build with: docker build tests/autobahn/. -t myimage
|
||||
# use in act: act -P ubuntu-latest=myimage
|
||||
|
||||
FROM node:12.6-buster-slim
|
||||
|
||||
COPY config/fuzzingserver.json /config/fuzzingserver.json
|
||||
RUN chmod +775 /config/fuzzingserver.json
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
docker \
|
||||
docker-compose
|
4
vlib/x/websocket/tests/autobahn/local_run/README.md
Normal file
4
vlib/x/websocket/tests/autobahn/local_run/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Run tests locally
|
||||
|
||||
Todo: document how, also how to use https://github.com/nektos/act
|
||||
|
11
vlib/x/websocket/tests/autobahn/ws_test/Dockerfile
Normal file
11
vlib/x/websocket/tests/autobahn/ws_test/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM thevlang/vlang:buster-dev
|
||||
|
||||
# ARG WORKSPACE_ROOT
|
||||
|
||||
# WORKDIR ${WORKSPACE_ROOT}
|
||||
COPY ./ /src/
|
||||
# COPY tests/autobahn/ws_test/run.sh /run.sh
|
||||
# RUN chmod +x /run.sh
|
||||
RUN v -autofree /src/tests/autobahn/autobahn_server.v
|
||||
RUN chmod +x /src/tests/autobahn/autobahn_server
|
||||
ENTRYPOINT [ "/src/tests/autobahn/autobahn_server" ]
|
Reference in New Issue
Block a user