Created
December 29, 2009 05:32
-
-
Save honzakral/265168 to your computer and use it in GitHub Desktop.
Script for paralel execution of django's test suite.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
## | |
# Script for paralel execution of django's test suite. | |
# | |
# Usage: place it in the same directory as your django checkout (not inside) | |
# and run it | |
# | |
# Params: you can optionally supply number of processes to spawn | |
# | |
# Gotchas: to use this script, every test process must use different database | |
# either use :memory: and sqlite or make your db name unique (os.getpid()) | |
# | |
# Author: Honza Kral <[email protected]> | |
# | |
# Enjoy! | |
## | |
#number of sub processes to spawn | |
PARALEL=${1:-2} | |
# list of PIDs of the test processes | |
typeset -A PIDS | |
# cleanup function | |
function kill_tests { | |
kill "${PIDS[@]}" | |
exit 2 | |
} | |
# kill if being killed | |
trap kill_tests TERM INT | |
# always cleanup | |
trap 'rm /tmp/django_tests_*' EXIT | |
apps=$( ( | |
# find all the app in tests directory | |
find django/tests -mindepth 3 -maxdepth 3 -name 'models.py' | |
# all the contrib apps | |
find django/django/contrib -maxdepth 2 -mindepth 2 -name tests -o -name tests.py | |
) | cut -d '/' -f 4 ) | |
# split them into at most $PARALEL files | |
num=$(echo "$apps" | wc -l) | |
# randomize apps to avoid clustering of easy and difficult apps | |
echo "$apps" | sort --random-sort | split -l $(( num / PARALEL + 1)) - /tmp/django_tests_ | |
# run the tests in paralel | |
for app_file in /tmp/django_tests_* | |
do | |
django/tests/runtests.py $(cat $app_file) & | |
PIDS[${#PIDS[@]}]=$! | |
done | |
# wait for all the tests to finish | |
wait "${PIDS[@]}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment