From 6d0a3f6920d72a86ada2b706dc7f774d6be08174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Caetano?= Date: Mon, 10 Dec 2018 14:08:32 -0200 Subject: [PATCH] Chore: Manual WS echo server * Running a websocket echo server manually. --- .travis.yml | 2 ++ Example/Podfile.lock | 8 +++--- RxWebSocket.podspec | 2 +- RxWebSocket.xcodeproj/project.pbxproj | 6 ++--- .../xcschemes/RxWebSocket-iOS.xcscheme | 6 ++--- RxWebSocketTests/RxWebSocketTests.swift | 2 +- echoserver.py | 25 +++++++++++++++++++ install_dependencies.sh | 16 ++++++------ requirements.txt | 3 +-- server.sh | 13 +++++++--- 10 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 echoserver.py diff --git a/.travis.yml b/.travis.yml index 081a85b..119ad09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ osx_image: xcode10.1 language: objective-c +python: + - "3.6" cache: directories: diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 7eea58f..1789e23 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -5,9 +5,9 @@ PODS: - RxSwift (4.4.0): - RxAtomic (~> 4.4) - RxWebSocket (2.0.0): - - RxCocoa (~> 4.0) - - RxSwift (~> 4.0) - - Starscream (~> 3.0) + - RxCocoa (~> 4.3) + - RxSwift (~> 4.3) + - Starscream (~> 3.0.6) - Starscream (3.0.6) DEPENDENCIES: @@ -28,7 +28,7 @@ SPEC CHECKSUMS: RxAtomic: eacf60db868c96bfd63320e28619fe29c179656f RxCocoa: df63ebf7b9a70d6b4eeea407ed5dd4efc8979749 RxSwift: 5976ecd04fc2fefd648827c23de5e11157faa973 - RxWebSocket: e8fef4ac562816a134e0a42cbab1b63a259488af + RxWebSocket: 77128a301abc8f13715bbf961f4fc9910429aa04 Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5 PODFILE CHECKSUM: 3733fdc28b1729df6cd665082d17f2f11ed36bef diff --git a/RxWebSocket.podspec b/RxWebSocket.podspec index 288b509..249f1bc 100644 --- a/RxWebSocket.podspec +++ b/RxWebSocket.podspec @@ -42,7 +42,7 @@ Pod::Spec.new do |s| # Dependencies - s.dependency 'Starscream', '~> 3.06' + s.dependency 'Starscream', '~> 3.0.6' s.dependency 'RxSwift', '~> 4.3' s.dependency 'RxCocoa', '~> 4.3' end diff --git a/RxWebSocket.xcodeproj/project.pbxproj b/RxWebSocket.xcodeproj/project.pbxproj index ad3c830..dc61860 100644 --- a/RxWebSocket.xcodeproj/project.pbxproj +++ b/RxWebSocket.xcodeproj/project.pbxproj @@ -510,7 +510,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "sh \"${PROJECT_DIR}/server.sh\" start"; + shellScript = "sh \"${PROJECT_DIR}/server.sh\" start\n"; }; F219FCD71FB4BA97000255A1 /* [WS] Start echoserver */ = { isa = PBXShellScriptBuildPhase; @@ -524,7 +524,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "sh \"${PROJECT_DIR}/server.sh\" start"; + shellScript = "sh \"${PROJECT_DIR}/server.sh\" start\n"; }; F219FCD81FB4C558000255A1 /* Check dependencies */ = { isa = PBXShellScriptBuildPhase; @@ -595,7 +595,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "sh \"${PROJECT_DIR}/server.sh\" start\n"; + shellScript = "#sh \"${PROJECT_DIR}/server.sh\" start\n"; }; F2312FE91FB206AE0038FA6A /* Swiftlint */ = { isa = PBXShellScriptBuildPhase; diff --git a/RxWebSocket.xcodeproj/xcshareddata/xcschemes/RxWebSocket-iOS.xcscheme b/RxWebSocket.xcodeproj/xcshareddata/xcschemes/RxWebSocket-iOS.xcscheme index d255c5e..c0f88af 100644 --- a/RxWebSocket.xcodeproj/xcshareddata/xcschemes/RxWebSocket-iOS.xcscheme +++ b/RxWebSocket.xcodeproj/xcshareddata/xcschemes/RxWebSocket-iOS.xcscheme @@ -26,9 +26,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" - shouldUseLaunchSchemeArgsEnv = "YES" - codeCoverageEnabled = "YES"> + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -66,7 +65,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/RxWebSocketTests/RxWebSocketTests.swift b/RxWebSocketTests/RxWebSocketTests.swift index bb2879d..623f50d 100644 --- a/RxWebSocketTests/RxWebSocketTests.swift +++ b/RxWebSocketTests/RxWebSocketTests.swift @@ -56,7 +56,7 @@ class RxWebSocketTests: XCTestCase { // TODO // Starscream is returning `protocolError` for normal closing operations // https://github.com/daltoniam/Starscream/issues/488 - XCTAssertEqual(error!.type, ErrorType.protocolError) + XCTAssertEqual(error?.type, ErrorType.protocolError) } catch let e { XCTFail(e.localizedDescription) diff --git a/echoserver.py b/echoserver.py new file mode 100644 index 0000000..0dd0eb7 --- /dev/null +++ b/echoserver.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import asyncio +import websockets +import sys + +PORT = sys.argv[1] + +async def echo(websocket, path): + async for message in websocket: + await websocket.send(message) + +async def test_connection(): + async with websockets.connect('ws://127.0.0.1:'+PORT) as websocket: + await websocket.send('hello') + await websocket.recv() + +async def main(): + await websockets.serve(echo, '127.0.0.1', PORT) + await asyncio.wait_for(test_connection(), 3) + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) + loop.run_forever() diff --git a/install_dependencies.sh b/install_dependencies.sh index e4a504e..3037263 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -32,9 +32,9 @@ install_bundle() { fi } -# Autobahn Test Suite -install_wstest() { - echo 'Installing wstest' +# Websocket server +install_websocket() { + echo 'Installing Websocket server' if [[ -f venv/bin/wstest ]] || [ $(which wstest) ]; then echo ' -> wstest already installed' @@ -44,7 +44,7 @@ install_wstest() { if [ ! -f venv/bin/activate ]; then if [[ $(which virtualenv) ]]; then echo 'Creating virtual env' - exe virtualenv "$(pwd)/venv" + exe virtualenv -p python3 "$(pwd)/venv" else echo ' -> virtualenv not installed.' fi @@ -56,15 +56,13 @@ install_wstest() { echo ' -> Virtual env not found. Attempting to install anyway' fi - if [[ ! $(which pip) ]]; then + if [[ ! $(which pip3) ]]; then echo 'Installing pip' exe easy_install --user pip && export PATH=/Users/travis/Library/Python/2.7/bin:${PATH} fi echo 'Installing wstest' - exe pip install -r requirements.txt - - verify "wstest" + exe pip3 install -r requirements.txt } # Homebrew @@ -121,7 +119,7 @@ if [[ "$1" == 'verify' ]]; then fi install_bundle -install_wstest +install_websocket install_swiftlint install_carthage echo 'Success! All requirements are installed' diff --git a/requirements.txt b/requirements.txt index 76f0de4..4789da4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -autobahntestsuite==0.7.6 -unittest2==1.1.0 +websockets==7.0 diff --git a/server.sh b/server.sh index 8cc6600..5ece042 100755 --- a/server.sh +++ b/server.sh @@ -9,7 +9,7 @@ open_port_pid() { } is_running() { - [ -f "$pid_file" ] || [ ! -z $(open_port_pid) ] + [ ! -z "$(open_port_pid)" ] } case "$1" in @@ -22,10 +22,17 @@ case "$1" in echo '\n-> Starting echoserver' LOGS=/tmp/wstest.log - venv/bin/wstest -m echoserver -w ws://127.0.0.1:$PORT > $LOGS 2>&1 & + python3 echoserver.py $PORT > $LOGS 2>&1 & echo "$!" > $pid_file - echo "Logs can be fount at $LOGS" + sleep .5 + + if ! is_running; then + echo 1 + cat $LOGS + fi + + echo "Logs can be found at $LOGS" ;; stop) if [ ! -f $pid_file ]; then