improve startup of test container
authorgggeek <giunta.gaetano@gmail.com>
Wed, 15 Feb 2023 15:45:27 +0000 (15:45 +0000)
committergggeek <giunta.gaetano@gmail.com>
Wed, 15 Feb 2023 15:45:27 +0000 (15:45 +0000)
.gitignore
tests/ci/docker/entrypoint.sh
tests/ci/vm.sh
tests/parse_args.php

index afccab0..416c9df 100644 (file)
@@ -13,3 +13,4 @@
 /.phpunit.result.cache
 /composer.lock
 /phpunit.xml
+/tests/ci/var/*
index d7d3bbc..b2c753a 100644 (file)
@@ -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"
index 57469d1..0fa0e6f 100755 (executable)
@@ -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
index 0fe331e..463e499 100644 (file)
@@ -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)) {