-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-timings
More file actions
executable file
·63 lines (45 loc) · 2.17 KB
/
test-timings
File metadata and controls
executable file
·63 lines (45 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
which dirname &> /dev/null || die "Unable to run dirname command - please install it"
export SCRIPTNAME="test-timings"
export SCRIPT_DIR=$(dirname "$(readlink -f "$0")") || { echo "Unable to identify basedir from $0" ; exit 1; }
. "${SCRIPT_DIR}/shared.sh" || { echo "Unable to load shared file shared.sh" ; exit 1; }
# Script to run a number of requests against a running server, and then check the log for
# This is a very crude script
check_on_path curl
check_on_path bc
check_on_path jq
set -e
set -o pipefail
OS_TO_TEST="$1"
test -z "${OS_TO_TEST}" && die "Usage: $0 <argument from server-script>"
debug "Finding server"
# Get information about the exposed port of the service from the compose file.
containerId=$(get_compose_container_id ${PROJECT_DIR}/docker/docker-compose.yml ${OS_TO_TEST})
port=$(get_compose_service_port ${PROJECT_DIR}/docker/docker-compose.yml ${OS_TO_TEST} 80)
URL="http://localhost:${port}/"
function run_requests() {
info "Running requests against server at ${URL}"
for FILE in ${SCRIPT_DIR}/../tests/requests/example/*.xml; do
debug "Running curl -X port --data @${FILE} -H 'Content-Type: text/xml' -H 'Accept: text/xml' ${URL}"
if curl -X port --data @${FILE} -H 'Content-Type: text/xml' -H 'Accept: text/xml' ${URL} &> /dev/null ; then
true
else
warn "Problem running curl -X port --data @${FILE} -H 'Content-Type: text/xml' -H 'Accept: text/xml' ${URL}"
fi
done
}
# Set a threshold of "less than a microsecond"
threshold=0.0000009
function check_timings() {
info "Checking log for container for TIMER statements"
JSONFILE=$(mktemp /tmp/tmp.test-timings.XXXXXX.json) || die "Unable to create temp JSON file with timing output"
debug "Creating JSON file in ${JSONFILE}"
echo "[" > ${JSONFILE}
docker logs ${containerId} 2> /dev/null | \
grep '"level":"TIMER"' | grep '"timing":{' | awk '{print $0","}' | sed '$ s/,$//' >> ${JSONFILE} \
|| die "No duration timings found in log - did you enable this in the abstract webserver class?"
echo "]" >> ${JSONFILE}
exec ${SCRIPT_DIR}/analyze-timings.py ${JSONFILE}
}
run_requests
check_timings