File: run_tests.sh

package info (click to toggle)
prometheus-flask-exporter 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 896 kB
  • sloc: python: 2,889; sh: 709; makefile: 4
file content (52 lines) | stat: -rwxr-xr-x 1,337 bytes parent folder | download
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
#!/bin/bash

cd "$(dirname "$0")"

_fail() {
    docker logs gunicorn-sample
    docker rm -f gunicorn-sample > /dev/null 2>&1
    exit 1
}

docker build -f Dockerfile -t gunicorn-sample ../../. > /dev/null || _fail
docker run -d --name gunicorn-sample -p 9200:9200 gunicorn-sample > /dev/null || _fail

echo 'Waiting for Gunicorn to start...'

for _ in $(seq 1 10); do
    PROCESS_COUNT=$(docker exec gunicorn-sample sh -c 'pgrep -a gunicorn | wc -l')
    if [ $PROCESS_COUNT -ge 5 ]; then
        break
    fi
done

echo 'Starting the tests...'

for _ in $(seq 1 10); do
    curl -s http://localhost:9200/test > /dev/null
    if [ "$?" != "0" ]; then
        echo 'Failed to request the test endpoint'
        _fail
    fi
done

curl -s http://localhost:9200/metrics \
  | grep -E 'flask_http_request_total\{.*status="200".*} 10.0' \
  > /dev/null

if [ "$?" != "0" ]; then
    echo 'The expected metrics are not found'
    _fail
fi

NUMBER_OF_FLASK_EXPORTER_INFO_METRICS=$(curl -s http://localhost:9200/metrics \
  | grep 'flask_exporter_info{' \
  | wc -l)

if [ "$NUMBER_OF_FLASK_EXPORTER_INFO_METRICS" -lt "1" ] || [ "$NUMBER_OF_FLASK_EXPORTER_INFO_METRICS" -gt 2 ]; then
    echo "Unexpected number of info metrics: $NUMBER_OF_FLASK_EXPORTER_INFO_METRICS"
    _fail
fi

docker rm -f gunicorn-sample > /dev/null
echo 'OK, all done'