1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#!/bin/bash
set -e
if [ -z "$(command -v python3)" ]; then
echo 'No python3 available, skipping this test'
exit
fi
test_random_port="$(( (RANDOM % 10000) + 13131 ))"
: "${TEST_SLEEPTIME:=0.1}"
: "${TEST_ADDRESS:=127.0.0.1}"
: "${TEST_PORT:=$test_random_port}"
SOCKET_ACTIVATE=${SOCKET_ACTIVATE:-socket-activate}
"$SOCKET_ACTIVATE" "--tcp:label=i-mellon:$TEST_ADDRESS/$TEST_PORT" "--udp:label=i-friend:$TEST_ADDRESS/$TEST_PORT" -- python3 "${PWD}/tests/test_python.py" &
jobpid="$(jobs -p)"
sleep "$TEST_SLEEPTIME"
if ! kill -0 "$jobpid"; then
echo "The $SOCKET_ACTIVATE program exited before the first test" 1>&2
exit 1
fi
nc -4 -W1 "$TEST_ADDRESS" "$TEST_PORT" | diff -u - <(echo 'mellon')
sleep "$TEST_SLEEPTIME"
if kill -0 "$jobpid" 2>/dev/null; then
echo "The $SOCKET_ACTIVATE program did not exit after the first test" 1>&2
exit 1
fi
"$SOCKET_ACTIVATE" "--tcp:label=i-mellon:$TEST_ADDRESS/$TEST_PORT" "--udp:label=i-friend:$TEST_ADDRESS/$TEST_PORT" -- python3 "${PWD}/tests/test_python.py" &
jobpid="$(jobs -p)"
sleep "$TEST_SLEEPTIME"
if ! kill -0 "$jobpid"; then
echo "The $SOCKET_ACTIVATE program exited before the second test" 1>&2
exit 1
fi
# UDP needs a trigger
echo | nc -4 -W1 -u "$TEST_ADDRESS" "$TEST_PORT" | diff -u - <(echo 'friend')
sleep "$TEST_SLEEPTIME"
if kill -0 "$jobpid" 2>/dev/null; then
echo "The $SOCKET_ACTIVATE program did not exit after the second test" 1>&2
exit 1
fi
|