libtest: Squash a race in temp webserver setup

Saw this in one of the PR contexts.

Closes: #1031
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-10-02 13:03:31 -04:00 committed by Atomic Bot
parent d4af84d428
commit 57937d0e63

View File

@ -145,9 +145,11 @@ setup_test_repository () {
run_temp_webserver() {
env PYTHONUNBUFFERED=1 setsid python -m SimpleHTTPServer 0 >${test_tmpdir}/httpd-output &
for x in $(seq 50); do
sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\) \.\.\.,\1,' < ${test_tmpdir}/httpd-output > ${test_tmpdir}/httpd-port
if ! cmp ${test_tmpdir}/httpd-output ${test_tmpdir}/httpd-port 1>/dev/null; then
break
if test -e ${test_tmpdir}/httpd-output; then
sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\) \.\.\.,\1,' < ${test_tmpdir}/httpd-output > ${test_tmpdir}/httpd-port
if ! cmp ${test_tmpdir}/httpd-output ${test_tmpdir}/httpd-port 1>/dev/null; then
break
fi
fi
sleep 0.1
done