1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

x.websocket: fix the uri port parsing problem. Make failures more informative (#6775)

This commit is contained in:
Tomas Hellström 2020-11-07 17:14:33 +01:00 committed by GitHub
parent 56817ea137
commit b47c23b73e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 45 deletions

View File

@ -518,40 +518,38 @@ jobs:
../v -autofree -experimental .
cd ..
# # TODO: ACTIVATE THIS AFTER MERGE
#
# websocket_autobahn:
# name: Autobahn integrations tests
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v2
#
# - name: Run autobahn services
# run: docker-compose -f ${{github.workspace}}/vlib/x/websocket/tests/autobahn/docker-compose.yml up -d
# - name: Build client test
# run: docker exec autobahn_client "v" "/src/tests/autobahn/autobahn_client.v"
# - name: Run client test
# run: docker exec autobahn_client "/src/tests/autobahn/autobahn_client"
# - 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: Test success
# run: docker exec autobahn_server "python" "/check_results.py"
#
# - name: Publish all reports
# uses: actions/upload-artifact@v2
# with:
# name: full report
# path: ${{github.workspace}}/reports
# - name: Publish report client
# uses: actions/upload-artifact@v2
# 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
# websocket_autobahn:
# name: Autobahn integrations tests
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v2
# - name: Run autobahn services
# run: docker-compose -f ${{github.workspace}}/vlib/x/websocket/tests/autobahn/docker-compose.yml up -d
# - name: Build client test
# run: docker exec autobahn_client "v" "/src/tests/autobahn/autobahn_client.v"
# - name: Run client test
# run: docker exec autobahn_client "/src/tests/autobahn/autobahn_client"
# - 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: Test success
# run: docker exec autobahn_server "python" "/check_results.py"
# - name: Publish all reports
# uses: actions/upload-artifact@v2
# with:
# name: full report
# path: ${{github.workspace}}/reports
# - name: Publish report client
# uses: actions/upload-artifact@v2
# 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

View File

@ -447,12 +447,15 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b
fn parse_uri(url string) ?&Uri {
u := urllib.parse(url)?
v := u.request_uri().split('?')
port := if u.str().starts_with('ws://') {
'80'
} else if u.str().starts_with('wss://') {
'443'
} else {
u.port()
mut port := u.port()
if port == '' {
port = if u.str().starts_with('ws://') {
'80'
} else if u.str().starts_with('wss://') {
'443'
} else {
u.port()
}
}
querystring := if v.len > 1 { '?' + v[1] } else { '' }
return &Uri{

View File

@ -16,6 +16,7 @@ fn start_server() ? {
// Here you can look att the client info and accept or not accept
// just returning a true/false
if s.resource_name != '/' {
panic('unexpected resource name in test')
return false
}
return true
@ -61,11 +62,15 @@ fn ws_test(uri string) ? {
println('Binary message: $msg')
}
})
ws.connect()
ws.connect() or {
panic('fail to connect')
}
go ws.listen()
text := ['a'].repeat(2)
for msg in text {
ws.write(msg.bytes(), .text_frame)?
ws.write(msg.bytes(), .text_frame) or {
panic('fail to write to websocket')
}
// sleep to give time to recieve response before send a new one
time.sleep_ms(100)
}