Skip to content

Commit 3421128

Browse files
Merge pull request #3559 from sebastian-miclea/PDB-5203
(PDB-5203) Added script to run locust tests
2 parents 0e1671d + f30f7a3 commit 3421128

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

ext/bin/run-locust-load-tests

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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"

locust/load-test/load-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_request(self, opts):
4141
params = {"limit": str(opts.get('limit')),
4242
"offset": str(opts.get('offset')),
4343
"order_by": json.dumps(opts.get('order_by')),
44-
"query": json.dumps(opts['query'])}
44+
"query": json.dumps(opts.get('query'))}
4545

4646
url = create_get_url(params, opts)
4747

0 commit comments

Comments
 (0)