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

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)
} }