#!/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