Skip to content

Commit

Permalink
Fix: ensure a single rmb-peer instance runs during the test_live_node…
Browse files Browse the repository at this point in the history
…s.sh script and that the Redis database is clean
  • Loading branch information
sameh-farouk committed Dec 12, 2024
1 parent fb9bf80 commit c0d5081
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions tools/rmb_tester/test_live_nodes.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash

case $1 in
main|dev|qa|test ) # Ok
;;
*)
# The wrong first argument.
echo 'Expected "dev", "qa", "test", or "main" as second arg' >&2
exit 1
main|dev|qa|test ) # Ok
;;
*)
# The wrong first argument.
echo 'Expected "dev", "qa", "test", or "main" as second arg' >&2
exit 1
esac


Expand All @@ -22,11 +22,20 @@ TIMEOUT="${TIMEOUT:-60}"
RMB_BIN="${RMB_BIN:-../../target/x86_64-unknown-linux-musl/release/rmb-peer}"
VERBOSE="${VERBOSE:-false}"
cleanup() {
set +e
if command -v deactivate &> /dev/null; then
deactivate
fi
jlist=$(jobs -p)
plist=$(ps --ppid $$ | awk '/[0-9]/{print $1}' | grep -v -E "^$$|^$(pgrep -f 'ps')|^$(pgrep -f 'awk')|^$(pgrep -f 'grep')$")
pids=${jlist:-$plist}
if [ -n "$pids" ]; then
echo "stop all bash managed jobs"
jlist=$(jobs -p)
plist=$(ps --ppid $$ | awk '/[0-9]/{print $1}')

kill ${jlist:-$plist}
kill $pids
else
echo "No processes to stop."
fi
exit
}

trap cleanup SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
Expand All @@ -38,10 +47,22 @@ echo "redis-server starting .."

redis-server --port 6379 > /dev/null 2>&1 &
sleep 3
# clear all databases
echo "Removes all keys in Redis"
redis-cli -p 6379 FLUSHALL
set -e

# ensure that RMB is not already running
if pgrep -x $(basename "$RMB_BIN") > /dev/null; then
echo "Another instance of rmb-peer is already running. Killing..."
pkill -x $(basename "$RMB_BIN")
fi

# ensure the MNEMONIC has no leading or trailing spaces
MNEMONIC="${MNEMONIC#"${MNEMONIC%%[![:space:]]*}"}"; MNEMONIC="${MNEMONIC%"${MNEMONIC##*[![:space:]]}"}"

# start rmb in background
echo "rmb-peer starting .."
echo "rmb-peer starting ("$1"net).."
$RMB_BIN -m "$MNEMONIC" --substrate "$SUBSTRATE_URL" --relay "$RELAY_URL" --redis "redis://localhost:6379" --debug &> $RMB_LOG_FILE &

# wait till peer establish connection to a relay
Expand All @@ -50,7 +71,6 @@ timeout --preserve-status 20 tail -f -n0 $RMB_LOG_FILE | grep -qe 'now connected
# start rmb_tester
source venv/bin/activate
echo "rmb_tester starting .."
python3 ./rmb_tester.py -d $(./scripts/twins.sh --likely-up $1) -c "zos.system.version" -t "$TIMEOUT" -e "$TIMEOUT" "$(if [[ "$VERBOSE" == "false" ]]; then echo "--short"; fi)"
deactivate
python3 ./rmb_tester.py -d $(./scripts/twins.sh --likely-up $1) -c "zos.system.version" -t "$TIMEOUT" -e "$TIMEOUT" $(if [[ "$VERBOSE" == "false" ]]; then echo "--short"; fi)

cleanup

0 comments on commit c0d5081

Please sign in to comment.