File: run.sh

package info (click to toggle)
python-confluent-kafka 2.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,232 kB
  • sloc: python: 36,571; ansic: 9,717; sh: 1,519; makefile: 198
file content (55 lines) | stat: -rwxr-xr-x 1,617 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
53
54
55
#!/bin/bash

source venv/bin/activate

testdir=$PWD
export LD_LIBRARY_PATH=$testdir/librdkafka-installation/lib
librdkafka_version=$(python3 -c 'from confluent_kafka import libversion; print(libversion()[0])')

if [[ -z $librdkafka_version ]]; then
    echo "No librdkafka version found.."
    exit 1
fi

set -u
run=true
topic="pysoak-$TESTID-$librdkafka_version"
logfile="${TESTID}.log.bz2"
limit=$((50 * 1024 * 1024)) # 50MB
export HOSTNAME=$(hostname)
echo "Starting soak client using topic $topic. Logging to $logfile."
set +x
while [ "$run" = true ]; do
    # Ignore SIGINT in children (inherited)
    trap "" SIGINT
    time opentelemetry-instrument $testdir/soakclient.py -i $TESTID -t $topic -r 80 -f $1 |& tee /dev/tty | bzip2 > $logfile &
    PID=$!
    terminate_last() {
        # List children of $PID only
        ps --ppid $PID -f | grep soakclient.py | grep -v grep | awk '{print $2}' | xargs kill
    }
    # On SIGINT kill only the first process of the pipe
    onsigint() {
        echo "Terminating soak client using topic $topic. Logging to $logfile."
        run=false
    }
    trap onsigint SIGINT
    # Await the result
    sleep 1
    size=$(stat -c%s "$logfile")
    while (( size < limit )) && [ "$run" = true ]; do
        sleep 1
        size=$(stat -c%s "$logfile")
    done
    terminate_last
    wait $PID
    ret=$?
    echo "Python client exited with status $ret"

    if [[ "$run" = true ]]; then
        echo "Rolling log file: $logfile"
        mv $logfile "${TESTID}.log.prev.bz2" || true
    fi
done
echo "Ending soak client using topic $topic. Logging to $logfile."
exit $ret