From b47c23b73ee530f364a7dff51d85551e344a4d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Hellstr=C3=B6m?= Date: Sat, 7 Nov 2020 17:14:33 +0100 Subject: [PATCH] x.websocket: fix the uri port parsing problem. Make failures more informative (#6775) --- .github/workflows/ci.yml | 72 ++++++++++++++--------------- vlib/x/websocket/websocket_client.v | 15 +++--- vlib/x/websocket/websocket_test.v | 9 +++- 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4440d15966..9cf53ec8a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index 5ddbfce4d5..b9f0139315 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -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{ diff --git a/vlib/x/websocket/websocket_test.v b/vlib/x/websocket/websocket_test.v index 5196cbc654..050da93f75 100644 --- a/vlib/x/websocket/websocket_test.v +++ b/vlib/x/websocket/websocket_test.v @@ -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) }