summaryrefslogtreecommitdiffstats
path: root/tests/run.sh
blob: 52e50d263060558e4ee8cc6cc132370f5fc70453 (plain)
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
#!/bin/sh
# Bring the local API stand-in up, run the driver against it, tear it down.
# Exits non-zero when anything fails. $1 is the driver, the rest is a prefix
# to run it under (valgrind, gdb, ...).

set -eu

here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
driver=$1
shift

fifo=$(mktemp -u)
mkfifo "$fifo"

python3 "$here/server.py" 0 >"$fifo" &
server=$!

cleanup() {
    kill "$server" 2>/dev/null || true
    wait "$server" 2>/dev/null || true
    rm -f "$fifo"
}
trap cleanup EXIT INT TERM

port=$(head -n 1 "$fifo")
if [ -z "$port" ]; then
    echo "server did not start" >&2
    exit 1
fi

echo "server on 127.0.0.1:$port"
"$@" "$driver" "http://127.0.0.1:$port"