Skip to content

Commit

Permalink
rebot test: Fix race condition in startup script
Browse files Browse the repository at this point in the history
if the server is instrumented with ASAN/TSAN it apparently takes longer
to print out the port number.

Add a loop with timeout to check for the port before continuing

Fixes #176
  • Loading branch information
phako committed Sep 23, 2020
1 parent e12b649 commit bbf050c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tests/scripts/testRebotBackend.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

TEST_RESULT=0
MAX_PORT_RETRY_COUNT=20

for PROTOCO_VERSION in 0 1; do
#start the server with the protocol version to test against
Expand All @@ -9,30 +10,40 @@ for PROTOCO_VERSION in 0 1; do
output=`mktemp`
./RebotDummyServer -m ./mtcadummy_rebot.map -V $PROTOCO_VERSION -p 0 >$output &
SERVER_PID=$!
sleep .1
PORT_RETRY_COUNT=0
PORT=""

# We take the port from the server and modify the DMAP files accordingly.
# It is passed on to the "subtests" as well as the server port itself
PORT=`awk '/^PORT /{print $2}' $output`
while [ $PORT_RETRY_COUNT -le $MAX_PORT_RETRY_COUNT ] && [ -z $PORT ]; do
sleep .5
PORT=`awk '/^PORT /{print $2}' $output`
let PORT_RETRY_COUNT+=1
done

if [ -z $PORT ] ; then
echo "Failed to spawn RebotDummyServer within 10s. Expect failures below"
fi

DMAP=`mktemp -p . -t XXXXXXXXX.dmap`
echo "Using server port $PORT"
echo "Using dmap file $DMAP"

sed -e "s|,5001|,$PORT|g" dummies.dmap > "$DMAP"

# run the test now; mskrebot uses ip address of the server in the dmap file
# run the test now; mskrebot uses ip address of the server in the dmap file
./testRebotBackend mskrebot "$DMAP" "$PORT"
if [ $? -ne 0 ] ; then # The above test failed;
echo "Testing backed using the IP addess with protocol version ${PROTOCO_VERSION} failed!"
TEST_RESULT=$(( ( $TEST_RESULT + 1 ) + ( ${PROTOCO_VERSION} *10 ) ))
fi
fi

# mskrebot1 uses hostname of the server in the dmap file
# mskrebot1 uses hostname of the server in the dmap file
./testRebotBackend mskrebot1 "$DMAP" "$PORT"
if [ $? -ne 0 ] ; then # The above test failed;
echo "Testing backed using the hostname with protocol version ${PROTOCO_VERSION} failed!"
TEST_RESULT=$(( ( $TEST_RESULT + 2 ) + ( ${PROTOCO_VERSION} *10 ) ))
fi
fi

./testRebotBackendCreation "$DMAP" "$PORT"
if [ $? -ne 0 ] ; then # The above test failed;
Expand All @@ -46,7 +57,7 @@ for PROTOCO_VERSION in 0 1; do
#a small sleep so the port is actually freed for the next server which is
#starting in the next loop iteration
sleep .1

done


Expand Down

0 comments on commit bbf050c

Please sign in to comment.