#!/bin/sh

set -e

# Fixture for the pkgos-run-tests unit tests: it proves that the runner
# prints its progress lines while the suite runs, and not only once it
# is finished. When it is run through test_parallel_live_progress, the
# runner's output goes to the file pointed at by PKGOS_RUN_TESTS_LOG,
# and this test waits until it sees its own Running line in there: as
# the runner prints that line before starting a test, it must already
# be visible in the log while this test runs. When
# PKGOS_RUN_TESTS_LOG is unset, this test is found by
# openstack-pkg-tools's own test suite, which runs without it: just
# pass.
LOG=${PKGOS_RUN_TESTS_LOG}
if [ -z "${LOG}" ] ; then
	exit 0
fi
i=0
while [ "${i}" -lt 100 ] ; do
	if grep -q "=== Running .*suite-c/test_progress" "${LOG}" 2>/dev/null ; then
		exit 0
	fi
	i=$(( ${i} + 1 ))
	sleep 0.1
done
echo "The runner did not print a Running line for this test while it was running."
exit 1
