mirror of
https://github.com/flatpak/flatpak.git
synced 2026-03-16 22:19:47 -04:00
When under load (for example running parallel tests) it can take a while to get the web server ready. Signed-off-by: Simon McVittie <smcv@collabora.com> Closes: #1760 Approved by: alexlarsson
32 lines
1.0 KiB
Bash
Executable File
32 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
dir=$1
|
|
test_tmpdir=$(pwd)
|
|
|
|
cd ${dir}
|
|
env PYTHONUNBUFFERED=1 setsid python -m SimpleHTTPServer 0 >${test_tmpdir}/httpd-output &
|
|
child_pid=$!
|
|
echo "Web server pid: $child_pid" >&2
|
|
|
|
for x in $(seq 300); do
|
|
echo "Waiting for web server ($x/300)..." >&2
|
|
# Snapshot the output
|
|
cp ${test_tmpdir}/httpd-output{,.tmp}
|
|
sed -ne 's/^/# httpd-output.tmp: /' < ${test_tmpdir}/httpd-output.tmp >&2
|
|
echo >&2
|
|
# If it's non-empty, see whether it matches our regexp
|
|
if test -s ${test_tmpdir}/httpd-output.tmp; then
|
|
sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\) \.\.\.,\1,' < ${test_tmpdir}/httpd-output.tmp > ${test_tmpdir}/httpd-port
|
|
if ! cmp ${test_tmpdir}/httpd-output.tmp ${test_tmpdir}/httpd-port 1>/dev/null; then
|
|
# If so, we've successfully extracted the port
|
|
break
|
|
fi
|
|
fi
|
|
sleep 0.1
|
|
done
|
|
port=$(cat ${test_tmpdir}/httpd-port)
|
|
echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
|
|
echo "$child_pid" > ${test_tmpdir}/httpd-pid
|