Skip to content

Commit

Permalink
fix: Make WebSocketTests work in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Cipolleschi committed Apr 27, 2022
1 parent ecf3293 commit fadfb71
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ jobs:
# -------------------------
# JOBS: iOS Unit Tests
# -------------------------
test_ios_unit:
ios_unit_and_integration_tests:
executor: reactnativeios
parameters:
use_frameworks:
Expand Down Expand Up @@ -1252,16 +1252,16 @@ workflows:
- build_npm_package
- test_ios_rntester
- build_ios
- test_ios_unit:
- ios_unit_and_integration_tests:
run_unit_tests: true
requires:
- build_ios
# requires:
# - build_ios
# DISABLED: USE_FRAMEWORKS=1 not supported by Flipper
# - build_ios:
# name: build_ios_frameworks
# use_frameworks: true
# - test_ios_unit:
# name: test_ios_unit_frameworks
# - ios_unit_and_integration_tests:
# name: ios_unit_and_integration_tests_frameworks
# use_frameworks: true
# run_unit_tests: true
# requires:
Expand Down
9 changes: 9 additions & 0 deletions IntegrationTests/WebSocketTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class WebSocketTest extends React.Component<{...}, State> {

_connect = () => {
const socket = new WebSocket(this.state.url);
console.log(`>>> Socket server url should be: ${this.state.url}`);
WS_EVENTS.forEach(ev => socket.addEventListener(ev, this._onSocketEvent));
this.setState({
socket,
Expand Down Expand Up @@ -115,31 +116,39 @@ class WebSocketTest extends React.Component<{...}, State> {
}

testConnect: () => void = () => {
console.log('>>> Testing connect...');
this._connect();
this._waitFor(this._socketIsConnected, 5, connectSucceeded => {
if (!connectSucceeded) {
TestModule.markTestPassed(false);
console.log('>>> Connect test failed.');
return;
}
console.log('>>> Connect test ended successfully.');
this.testSendAndReceive();
});
};

testSendAndReceive: () => void = () => {
console.log('>>> Testing sendAndReceive...');
this._sendTestMessage();
this._waitFor(this._receivedTestExpectedResponse, 5, messageReceived => {
if (!messageReceived) {
TestModule.markTestPassed(false);
console.log('>>> Test sendAndReceive failed.');
return;
}
console.log('>>> Test sendAndReceive ended successfully.');
this.testDisconnect();
});
};

testDisconnect: () => void = () => {
console.log('>>> Testing disconnect...');
this._disconnect();
this._waitFor(this._socketIsDisconnected, 5, disconnectSucceeded => {
TestModule.markTestPassed(disconnectSucceeded);
console.log('>>> Test disconnect ended successfully.');
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# Set terminal title
echo -en "\033]0;Web Socket Test Server\a"
clear

THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
pushd "$THIS_DIR"
./websocket_integration_test_server.js
popd

echo "Process terminated. Press <enter> to close the window"
read
26 changes: 23 additions & 3 deletions scripts/objc-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ waitForPackager() {
echo "Packager is ready!"
}

waitForWebSocketServer() {
local -i max_attempts=60
local -i attempt_num=1

until curl -s http://localhost:5555 | grep "Upgrade Required" -q; do
if (( attempt_num == max_attempts )); then
echo "WebSocket Server did not respond in time. No more attempts left."
exit 1
else
(( attempt_num++ ))
echo "WebSocket Server did not respond. Retrying for attempt number $attempt_num..."
sleep 1
fi
done

echo "WebSocket Server is ready!"
}

runTests() {
# shellcheck disable=SC1091
source "./scripts/.tests.env"
Expand Down Expand Up @@ -102,11 +120,13 @@ main() {
# Otherwise, just build RNTester and exit
if [ "$1" = "test" ]; then

# Start the packager
yarn start --max-workers=1 || echo "Can't start packager automatically" &
# Start the WebSocket test server
open "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically"
echo "Launch WebSocket Server"
sh "./IntegrationTests/launchWebSocketServer.sh" &
waitForWebSocketServer

# Start the packager
yarn start --max-workers=1 || echo "Can't start packager automatically" &
waitForPackager
preloadBundles

Expand Down

0 comments on commit fadfb71

Please sign in to comment.