Skip to content

Instantly share code, notes, and snippets.

@jacobkahn
Last active February 29, 2020 05:51
Show Gist options
  • Save jacobkahn/4e9a89039c4fec322fa5dcf452480436 to your computer and use it in GitHub Desktop.
Save jacobkahn/4e9a89039c4fec322fa5dcf452480436 to your computer and use it in GitHub Desktop.
Run some stuff a bunch of times and see if it prints FAIL anywhere
#!/bin/sh
# Usage:
# bash ./test_many.sh [test_name] [num_runs=100] [parallelism=32]
#
# Example:
# bash ./test_many.sh 2B
test_name=$1
num_runs="${2:-100}"
output_logdir="/tmp/test_result"
parallelism="${3:-32}"
# Dir for test output
echo "Creating output dir."
mkdir -p ${output_logdir}
# wipe the dir for any preexisting stuff, just in case
echo "Removing existing files."
rm -f ${output_logdir}/*.out
# run
echo "Running ${num_runs} jobs of test with name \"${test_name}\" with parallelism ${parallelism}..."
seq $num_runs | xargs -P ${parallelism} -n 1 -I{} sh -c "go test -run test_name > ${output_logdir}/test_output_{}.out"
# wait for all background jobs to finish
wait
echo "Background jobs have finished."
# output files are populated, check them with a threadpool
echo "Checking output files for failed tests..."
output=$(find ${output_logdir} -type f -name "*.out" | xargs -P 8 -n 1 -I{} sh -c "cat {} | grep -F FAIL")
if [[ $(echo ${output}) ]]; then
echo "Failed tests found:"
echo "${output}"
else
echo "All passed!!!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment