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

pull/6782/head
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 . ../v -autofree -experimental .
cd .. cd ..
# # TODO: ACTIVATE THIS AFTER MERGE # websocket_autobahn:
# # name: Autobahn integrations tests
# websocket_autobahn: # runs-on: ubuntu-latest
# name: Autobahn integrations tests # steps:
# runs-on: ubuntu-latest # - name: Checkout
# steps: # uses: actions/checkout@v2
# - 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: Run autobahn services # - name: Build client test
# run: docker-compose -f ${{github.workspace}}/vlib/x/websocket/tests/autobahn/docker-compose.yml up -d # run: docker exec autobahn_client "v" "/src/tests/autobahn/autobahn_client.v"
# - name: Build client test # - name: Run client test
# run: docker exec autobahn_client "v" "/src/tests/autobahn/autobahn_client.v" # run: docker exec autobahn_client "/src/tests/autobahn/autobahn_client"
# - name: Run client test # - name: Run server test
# run: docker exec autobahn_client "/src/tests/autobahn/autobahn_client" # run: docker exec autobahn_server "wstest" "-m" "fuzzingclient" "-s" "/config/fuzzingclient.json"
# - name: Run server test # - name: Copy reports
# run: docker exec autobahn_server "wstest" "-m" "fuzzingclient" "-s" "/config/fuzzingclient.json" # run: docker cp autobahn_server:/reports ${{github.workspace}}/reports
# - name: Copy reports # - name: Test success
# run: docker cp autobahn_server:/reports ${{github.workspace}}/reports # run: docker exec autobahn_server "python" "/check_results.py"
# - name: Test success
# run: docker exec autobahn_server "python" "/check_results.py" # - name: Publish all reports
# # uses: actions/upload-artifact@v2
# - name: Publish all reports # with:
# uses: actions/upload-artifact@v2 # name: full report
# with: # path: ${{github.workspace}}/reports
# name: full report # - name: Publish report client
# path: ${{github.workspace}}/reports # uses: actions/upload-artifact@v2
# - name: Publish report client # with:
# uses: actions/upload-artifact@v2 # name: client
# with: # path: ${{github.workspace}}/reports/clients/index.html
# name: client # - name: Publish report server
# path: ${{github.workspace}}/reports/clients/index.html # uses: actions/upload-artifact@v2
# - name: Publish report server # with:
# uses: actions/upload-artifact@v2 # name: server
# with: # path: ${{github.workspace}}/reports/servers/index.html
# name: server
# path: ${{github.workspace}}/reports/servers/index.html

View File

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

View File

@ -16,6 +16,7 @@ fn start_server() ? {
// 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
if s.resource_name != '/' { if s.resource_name != '/' {
panic('unexpected resource name in test')
return false return false
} }
return true return true
@ -61,11 +62,15 @@ fn ws_test(uri string) ? {
println('Binary message: $msg') println('Binary message: $msg')
} }
}) })
ws.connect() ws.connect() or {
panic('fail to connect')
}
go ws.listen() go ws.listen()
text := ['a'].repeat(2) text := ['a'].repeat(2)
for msg in text { 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 // sleep to give time to recieve response before send a new one
time.sleep_ms(100) time.sleep_ms(100)
} }