Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Chore: Manual WS echo server
Browse files Browse the repository at this point in the history
* Running a websocket echo server manually.
  • Loading branch information
fjcaetano committed Dec 10, 2018
1 parent e81ef11 commit 6d0a3f6
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
osx_image: xcode10.1
language: objective-c
python:
- "3.6"

cache:
directories:
Expand Down
8 changes: 4 additions & 4 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -28,7 +28,7 @@ SPEC CHECKSUMS:
RxAtomic: eacf60db868c96bfd63320e28619fe29c179656f
RxCocoa: df63ebf7b9a70d6b4eeea407ed5dd4efc8979749
RxSwift: 5976ecd04fc2fefd648827c23de5e11157faa973
RxWebSocket: e8fef4ac562816a134e0a42cbab1b63a259488af
RxWebSocket: 77128a301abc8f13715bbf961f4fc9910429aa04
Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5

PODFILE CHECKSUM: 3733fdc28b1729df6cd665082d17f2f11ed36bef
Expand Down
2 changes: 1 addition & 1 deletion RxWebSocket.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions RxWebSocket.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<PostActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
Expand Down Expand Up @@ -66,7 +65,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion RxWebSocketTests/RxWebSocketTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions echoserver.py
Original file line number Diff line number Diff line change
@@ -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()
16 changes: 7 additions & 9 deletions install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
autobahntestsuite==0.7.6
unittest2==1.1.0
websockets==7.0
13 changes: 10 additions & 3 deletions server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open_port_pid() {
}

is_running() {
[ -f "$pid_file" ] || [ ! -z $(open_port_pid) ]
[ ! -z "$(open_port_pid)" ]
}

case "$1" in
Expand All @@ -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
Expand Down

0 comments on commit 6d0a3f6

Please sign in to comment.