Skip to content

Commit a8284e6

Browse files
committed
add a simple shell script to test websocket proxy
1 parent 5423a31 commit a8284e6

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

ws/proxyConfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"remote_urls": {
3-
"echo.localhost:8008": "ws://localhost:9009",
4-
"cobra.localhost:8008": "ws://localhost:8765"
3+
"echo.localhost:8008": "ws://localhost:8009",
4+
"cobra.localhost:8008": "ws://localhost:5678"
55
}
66
}

ws/test_ws_proxy.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
# This test requires cobra to be available
4+
which cobra > /dev/null || {
5+
echo cobra is not installed on this machine.
6+
exit 0
7+
}
8+
9+
# Handle Ctrl-C by killing all sub-processing AND exiting
10+
trap cleanup INT
11+
12+
function cleanup {
13+
exit_code=${1:-1}
14+
echo "Killing all servers (ws and cobra)"
15+
echo
16+
kill `cat /tmp/pidfile.proxy` &>/dev/null
17+
kill `cat /tmp/pidfile.echo_server` &>/dev/null
18+
kill `cat /tmp/pidfile.cobra` &>/dev/null
19+
kill `cat /tmp/pidfile.connect.echo` &>/dev/null
20+
kill `cat /tmp/pidfile.connect.cobra` &>/dev/null
21+
exit ${exit_code}
22+
}
23+
24+
ws proxy_server --pidfile /tmp/pidfile.proxy --config_path proxyConfig.json &
25+
ws echo_server --pidfile /tmp/pidfile.echo_server --port 8009 &
26+
cobra -v run --pidfile /tmp/pidfile.cobra --port 5678 &
27+
28+
# Wait for the servers to be up
29+
sleep 1
30+
31+
# unbuffer comes with expect (written in tcl)
32+
echo 'hello' | unbuffer ws connect --pidfile /tmp/pidfile.connect.echo ws://echo.localhost:8008 &
33+
34+
echo 'hello' | unbuffer ws connect --pidfile /tmp/pidfile.connect.cobra ws://cobra.localhost:8008 &
35+
36+
# Wait
37+
sleep 2
38+
39+
cleanup

0 commit comments

Comments
 (0)