Skip to content

Commit c419b14

Browse files
authored
Merge pull request #32 from dimacurrentai/fix_test
Fixed the Websocket test.
2 parents e79d1e2 + e0c4c77 commit c419b14

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ target/
77
# Using the `Dockerfile.template` in the root directory now.
88
Dockerfile
99

10+
# Sigh, some `run.sh` scripts do use `npm i`.
11+
node_modules
12+
package.json
13+
package-lock.json
14+
1015
# To make sure all `lib` directories are effectively symlinks to `$REPO_ROOT/lib`.
1116
# Unless they are explicit copies, since otherwise Docker-based builds would not succeed.
1217
step*/code/src/lib

step10_websocket/run.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@ set -e
1212
[ -L code/templates ] && (unlink code/templates && echo 'Symlink of `code/templates` removed.') || echo 'No `code/templates` symlink to remove.'
1313
[ -d code/templates ] && echo 'The `code/templates` dir exists, using it.' || (cp -r ../lib/templates code/ && echo 'Copied `../lib/templates` into `code/templates`.')
1414

15+
echo '`npm i ws`.'
16+
npm i ws
17+
echo '`npm i ws`: success.'
18+
1519
docker build -f ../Dockerfile.template . -t demo
1620

17-
docker run --rm --network=bridge -p 3000:3000 -t demo &
21+
function cleanup {
22+
echo -n "trap: stopping the docker container "
23+
docker stop -t 0 rust_experiments_docker_container
24+
echo "docker stop done"
25+
}
26+
trap cleanup EXIT
27+
28+
docker run --rm --name rust_experiments_docker_container --network=bridge -p 3000:3000 -t demo &
1829
PID=$!
1930

2031
while true ; do
@@ -27,17 +38,18 @@ while true ; do
2738
echo "server not yet healthy"
2839
done
2940

30-
S="$(npx wscat -c ws://0.0.0.0:3000/test_ws | head -n 1)"
41+
WS_NODEJS_CODE="const WS = require('ws'); (new WS('ws://localhost:3000/test_ws')).on('message', buf => console.log(buf.toString()));"
42+
43+
S="$(node -e "$WS_NODEJS_CODE" | head -n 1)"
3144
G="magic"
3245

3346
if [ "$S" != "$G" ] ; then
3447
echo "TEST FAILED, expected '$G', seeing '$S'."
48+
exit 1
3549
fi
3650

3751
curl -s localhost:3000/quit
3852

39-
wait $PID
53+
trap - EXIT
4054

41-
if [ "$S" = "$G" ] ; then
42-
exit 1
43-
fi
55+
wait $PID

0 commit comments

Comments
 (0)