tests: run all tests in parallel, if available

If either the moreutils or GNU parallel utility are available, run all
tests in parallel.  On my eight core machine this makes for a ~x7
speed-up in the full test suite (1m24s -> 12s).

The design of the test suite makes this parallelization trivial.
This commit is contained in:
Jameson Graef Rollins 2019-05-04 20:57:43 +00:00 committed by David Bremner
parent 591388ccd1
commit 908d930d22

View file

@ -40,7 +40,16 @@ fi
trap 'e=$?; kill $!; exit $e' HUP INT TERM trap 'e=$?; kill $!; exit $e' HUP INT TERM
# Run the tests # Run the tests
for test in $TESTS; do if command -v parallel >/dev/null ; then
if parallel -h | grep -q GNU ; then
echo "INFO: running tests with GNU parallel"
printf '%s\n' $TESTS | $TEST_TIMEOUT_CMD parallel
else
echo "INFO: running tests with moreutils parallel"
$TEST_TIMEOUT_CMD parallel -- $TESTS
fi
else
for test in $TESTS; do
$TEST_TIMEOUT_CMD $test "$@" & $TEST_TIMEOUT_CMD $test "$@" &
wait $! wait $!
# If the test failed without producing results, then it aborted, # If the test failed without producing results, then it aborted,
@ -50,7 +59,8 @@ for test in $TESTS; do
if [[ $RES != 0 && ! -e "$NOTMUCH_BUILDDIR/test/test-results/$testname" ]]; then if [[ $RES != 0 && ! -e "$NOTMUCH_BUILDDIR/test/test-results/$testname" ]]; then
exit $RES exit $RES
fi fi
done done
fi
trap - HUP INT TERM trap - HUP INT TERM
# Report results # Report results