|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eo pipefail |
| 4 | + |
| 5 | +usage() { |
| 6 | + cat <<EOF |
| 7 | +
|
| 8 | +Usage: $(basename "$0") [SHA] |
| 9 | +
|
| 10 | + Will run locus tests. There is a first run of 5 minutes due to the warm-up |
| 11 | + period for JVM. Only the second run is the actual test run. |
| 12 | + This script should be run from the puppetdb root dir. |
| 13 | +
|
| 14 | +EOF |
| 15 | +} |
| 16 | + |
| 17 | +if [ "$1" = "--help" ]; then |
| 18 | + usage |
| 19 | + exit 0 |
| 20 | +fi |
| 21 | + |
| 22 | +on-exit() { |
| 23 | + kill_pdb |
| 24 | + if [ $pdb_script_pid ]; then kill -9 $pdb_script_pid; fi |
| 25 | +} |
| 26 | + |
| 27 | +kill_pdb() { |
| 28 | + pdb_pid=`lsof -t -i:8080 || true` |
| 29 | + if [ $pdb_pid ]; then kill -9 $pdb_pid; fi |
| 30 | +} |
| 31 | +trap on-exit EXIT |
| 32 | + |
| 33 | +# If sha is not provided set the default to 6.x |
| 34 | +sha="6.x" |
| 35 | +if [ $1 ]; then |
| 36 | + echo "Using provided sha ${1}" |
| 37 | + sha=$1 |
| 38 | +else |
| 39 | + echo "Using default sha ${sha}" |
| 40 | +fi |
| 41 | + |
| 42 | +results_dir="/home/andrei.filipovici/performance_results" |
| 43 | +current_time=$(date +%Y-%m-%dT%H:%M:%S%z) |
| 44 | +output_dir="${results_dir}/${sha}-${current_time}" |
| 45 | + |
| 46 | +# Create the output dir if it does not exist |
| 47 | +mkdir -p "${output_dir}" |
| 48 | + |
| 49 | +# pg_script needs to be available in PATH for pdb_script to use it |
| 50 | +export PATH=$PATH:/home/andrei.filipovici/pg_script |
| 51 | + |
| 52 | +echo "Getting latest revisions" |
| 53 | +git fetch --all |
| 54 | +git status |
| 55 | +git reset --hard origin/"$sha" |
| 56 | + |
| 57 | +echo "Killing off any other running instances of puppetdb" |
| 58 | +kill_pdb |
| 59 | + |
| 60 | +# Start the puppetdb server |
| 61 | +../pdb-script/pdb-script --name 100000 run >"$output_dir/pdb_log.txt" 2>&1 & |
| 62 | +pdb_script_pid=$! |
| 63 | + |
| 64 | +printf "Waiting for PDB startup (log: %q)\n" "$output_dir/pdb_log.txt" 2>&1 |
| 65 | +while ! grep -Fq "Finished database garbage collection" "$output_dir/pdb_log.txt"; do |
| 66 | + sleep 1 |
| 67 | + printf "." |
| 68 | + if [ "$(grep -F "Error during service start!!!" "$output_dir/pdb_log.txt")" ]; then |
| 69 | + echo "PDB failed during start-up." 1>&2 |
| 70 | + exit 2 |
| 71 | + fi |
| 72 | +done |
| 73 | +echo |
| 74 | + |
| 75 | +echo "Starting locust warm-up\n" |
| 76 | +# We use the same filename to have them overwritten by the test run. |
| 77 | +python3.6 ./locust/run-load-test -t 5m -u 20 --csv "$output_dir/locust" --html "$output_dir/locust.html" --only-summary -T all |
| 78 | + |
| 79 | +echo "Starting locust load tests\n" |
| 80 | +python3.6 ./locust/run-load-test -t 15m -u 20 --csv "$output_dir/locust" --html "$output_dir/locust.html" --only-summary -T all |
| 81 | +test_exit=$? |
| 82 | + |
| 83 | +if [ $test_exit -ne 0 ]; then |
| 84 | + printf "Tests exited with error. Check logs: %q\n" "$output_dir/pdb_log.txt" |
| 85 | +fi |
| 86 | + |
| 87 | +printf "Tests ran successfully. Output files are: %q_*.csv\n" "$output_dir/locust" |
0 commit comments