Skip to content

Instantly share code, notes, and snippets.

@dkua
Last active August 29, 2015 14:02
Show Gist options
  • Save dkua/add85fdb4db267c73e14 to your computer and use it in GitHub Desktop.
Save dkua/add85fdb4db267c73e14 to your computer and use it in GitHub Desktop.
Test script to test exit cases in QMD
#!/bin/bash
## Sample POST request to /scripts/qmd_bench.sh
##
## {
## "args": ["1", "10"],
## "callback_url": "http://192.168.88.88:9090"
## }
MIN=$1
MAX=$2
PID=$$
echo "Running under PID #$PID"
echo "Making file in tmp dir at $QMD_TMP"
'Test #$PID' >> $QMD_TMP/$PID
echo "Making file in store dir at $QMD_STORE"
'Test #$PID' >> $QMD_STORE/$PID
while [ $MAX -eq $MAX ]
do
NUM=`shuf -i $MIN-$MAX -n 1`
echo "Randomly selected $NUM"
if [ $NUM -eq 7 ]
then
# Success
echo "Job well done!"
exit 0
elif [ $NUM -eq 4 ]
then
# Error
echo "Error! Error!"
exit 1
elif [ $NUM -eq $MAX ]
then
# Crash the script
echo "Abandon ship! Abandon ship! Everyone for themselves!"
kill -SIGHUP $$
else
# Sleep
echo "zzzzzzzzzzzzzzzzz"
sleep $NUM
echo "zzzzzz..I'M AWAKE"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment