From bc15fbb86d958233548efb57cfdfa0abcd997e37 Mon Sep 17 00:00:00 2001 From: gggeek Date: Wed, 15 Feb 2023 15:45:27 +0000 Subject: [PATCH] improve startup of test container --- .gitignore | 1 + tests/ci/docker/entrypoint.sh | 12 ++++++++++++ tests/ci/vm.sh | 25 +++++++++++++++++++++++++ tests/parse_args.php | 4 ++-- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index afccab0a..416c9dfa 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ /.phpunit.result.cache /composer.lock /phpunit.xml +/tests/ci/var/* diff --git a/tests/ci/docker/entrypoint.sh b/tests/ci/docker/entrypoint.sh index d7d3bbcb..b2c753a3 100644 --- a/tests/ci/docker/entrypoint.sh +++ b/tests/ci/docker/entrypoint.sh @@ -4,6 +4,10 @@ USERNAME="${1:-docker}" echo "[$(date)] Bootstrapping the Test container..." +if [ -f "${TESTS_ROOT_DIR}/tests/ci/var/bootstrap_ok" ]; then + rm "${TESTS_ROOT_DIR}/tests/ci/var/bootstrap_ok" +fi + clean_up() { # Perform program exit housekeeping @@ -78,6 +82,14 @@ service privoxy start echo "[$(date)] Bootstrap finished" +# Create the file which can be used by the vm.sh script to check for end of bootstrap +if [ ! -d "${TESTS_ROOT_DIR}/tests/ci/var" ]; then + mkdir -p "${TESTS_ROOT_DIR}/tests/ci/var" + chown -R "${USERNAME}" "${TESTS_ROOT_DIR}/tests/ci/var" +fi +# @todo save to bootstrap_ok an actual error code if any of the commands above failed +touch "${TESTS_ROOT_DIR}/tests/ci/var/bootstrap_ok" && chown "${USERNAME}" "${TESTS_ROOT_DIR}/tests/ci/var/bootstrap_ok" + tail -f /dev/null & child=$! wait "$child" diff --git a/tests/ci/vm.sh b/tests/ci/vm.sh index 57469d19..0fa0e6f0 100755 --- a/tests/ci/vm.sh +++ b/tests/ci/vm.sh @@ -46,6 +46,24 @@ Environment variables: to be set before the 'build' action " } +wait_for_bootstrap() { + I=0 + while [ $I -le 60 ]; do + if [ -f "${ROOT_DIR}/tests/ci/var/bootstrap_ok" ]; then + echo '' + break; + fi + printf '.' + sleep 1 + I=$((I+1)) + done + if [ $I -eq 60 ]; then + echo "ERROR: Container did not finish bootstrapping within 60 seconds..." >&2 + return 1 + fi + return 0 +} + build() { stop docker build --build-arg PHP_VERSION --build-arg UBUNTU_VERSION -t "${IMAGE_NAME}" . @@ -68,11 +86,18 @@ build() { --env DEBUG=0 \ -v "${ROOT_DIR}":"${CONTAINER_WORKSPACE_DIR}" \ "${IMAGE_NAME}" + + if [ $? -eq 0 ]; then + wait_for_bootstrap + fi } start() { if docker inspect "${CONTAINER_NAME}" >/dev/null 2>/dev/null; then docker start "${CONTAINER_NAME}" + if [ $? -eq 0 ]; then + wait_for_bootstrap + fi else build fi diff --git a/tests/parse_args.php b/tests/parse_args.php index 0fe331ec..463e4998 100644 --- a/tests/parse_args.php +++ b/tests/parse_args.php @@ -16,7 +16,7 @@ * @copyright (C) 2007-2023 G. Giunta * @license code licensed under the BSD License: see file license.txt * - * @todo rename both the class and the file. PhpXmlRpc_TestArgParser ? + * @todo rename both the class and the file. PhpXmlRpc_TestConfigParser ? **/ class argParser { @@ -44,7 +44,7 @@ class argParser ); // check for command line params (passed as env vars) vs. web page input params (passed as GET/POST) - // Note that the only usecase for web-page mode is when this is used by benchmark.php + // Note that the only use-case for web-page mode is when this is used by benchmark.php if (!isset($_SERVER['REQUEST_METHOD'])) { foreach($_SERVER as $key => $val) { if (array_key_exists($key, $args)) { -- 2.47.0