From eb127103a048edd8a5607203c9d920b2fe4b3178 Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 16 Apr 2024 16:03:31 +0000 Subject: [PATCH] small improvements to test code and test container build --- .github/workflows/ci.yaml | 24 +++++++++++++++----- tests/WebTestCase.php | 9 ++++---- tests/ci/docker/entrypoint.sh | 35 +++++++++++++++++++----------- tests/ci/setup/install_packages.sh | 2 ++ tests/ci/vm.sh | 5 +++-- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3948c5f..cb21c94 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -131,6 +131,7 @@ jobs: #ps auxwww | grep fpm #pwd #sudo env + #systemctl list-units --all --type=service --no-pager | grep running #systemctl status apache2.service #ls -la /etc/apache2/mods-enabled #ls -la /etc/apache2/conf-enabled @@ -159,9 +160,10 @@ jobs: #- dependency: phpxmlrpc/jsonrpc - dependency: phpxmlrpc/polyfill-xmlrpc steps: + # NB: unusually, but intentionally, we do _not_ download the code of this very own repo into the workspace! + - name: download dependency, build its test vm and run its tests against the current commit run: | - systemctl list-units --all --type=service --no-pager | grep running # We test against the latest available release of dependents. # Arguably, we could (also?) test against their master branch, in case some fixes were pushed there # and not released yet, which make them work ok with us, but those tend to be tested when pushing @@ -172,11 +174,23 @@ jobs: sed -i -E -e 's|"phpxmlrpc/phpxmlrpc" *: *"source"|"phpxmlrpc/phpxmlrpc_": "source"|g' composer.json sed -i -E -e 's|"phpxmlrpc/phpxmlrpc" *: *".+|"phpxmlrpc/phpxmlrpc": "dev-master#${{ github.ref_name }} as 4.999"|g' composer.json sed -i -E -e 's|"phpxmlrpc/phpxmlrpc_" *: *"source"|"phpxmlrpc/phpxmlrpc": "source"|g' composer.json + # @todo either set COMPOSER_ROOT_VERSION env var, or inject `version` into composer.json, to allow + # composer to know that the top-level project is on `dev-master` chmod 755 ./tests/ci/vm.sh ./tests/ci/vm.sh build ./tests/ci/vm.sh start - # @todo this should not be necessary any more, as `start` waits for the app to be set up - sleep 30 - # echo the logs of the bootstrap of the container, as there might be useful info - ./tests/ci/vm.sh logs + # this should not be necessary any more, as `start` waits for the app to be set up + #sleep 30 ./tests/ci/vm.sh runtests + # NB: we do not stop the container, nor clean up the current folder, as we rely on each matrix case + # being executed in its own runner instance + + - name: failure troubleshooting + if: ${{ failure() }} + run: | + docker --version + docker ps + docker ps -a + ./tests/ci/vm.sh top + #./tests/ci/vm.sh exec env + ./tests/ci/vm.sh logs diff --git a/tests/WebTestCase.php b/tests/WebTestCase.php index 879c06b..9ef9148 100644 --- a/tests/WebTestCase.php +++ b/tests/WebTestCase.php @@ -40,14 +40,15 @@ protected function request($path, $method = 'GET', $payload = '', $emptyPageOk = curl_setopt($ch, CURLOPT_VERBOSE, 1); } $page = curl_exec($ch); + $info = curl_getinfo($ch); curl_close($ch); - $this->assertNotFalse($page); + $this->assertNotFalse($page, 'Curl request should not fail. Url: ' . @$info['url'] . ', Http code: ' . @$info['http_code']); if (!$emptyPageOk) { - $this->assertNotEquals('', $page); + $this->assertNotEquals('', $page, 'Retrieved web page should not be empty'); } - $this->assertStringNotContainsStringIgnoringCase('Fatal error', $page); - $this->assertStringNotContainsStringIgnoringCase('Notice:', $page); + $this->assertStringNotContainsStringIgnoringCase('Fatal error', $page, 'Retrieved web page should not contain a fatal error string'); + $this->assertStringNotContainsStringIgnoringCase('Notice:', $page, 'Retrieved web page should not contain a notice string'); return $page; } diff --git a/tests/ci/docker/entrypoint.sh b/tests/ci/docker/entrypoint.sh index b2c753a..0692dfa 100644 --- a/tests/ci/docker/entrypoint.sh +++ b/tests/ci/docker/entrypoint.sh @@ -20,6 +20,10 @@ clean_up() { echo "[$(date)] Stopping FPM" service php-fpm stop + if [ -f "${TESTS_ROOT_DIR}/tests/ci/var/bootstrap_ok" ]; then + rm "${TESTS_ROOT_DIR}/tests/ci/var/bootstrap_ok" + fi + echo "[$(date)] Exiting" exit } @@ -28,18 +32,18 @@ clean_up() { echo "[$(date)] Fixing filesystem permissions..." -ORIGPASSWD=$(cat /etc/passwd | grep "^${USERNAME}:") -ORIG_UID=$(echo "$ORIGPASSWD" | cut -f3 -d:) -ORIG_GID=$(echo "$ORIGPASSWD" | cut -f4 -d:) -CONTAINER_USER_HOME=$(echo "$ORIGPASSWD" | cut -f6 -d:) -CONTAINER_USER_UID=${CONTAINER_USER_UID:=$ORIG_UID} -CONTAINER_USER_GID=${CONTAINER_USER_GID:=$ORIG_GID} +ORIGPASSWD="$(grep "^${USERNAME}:" /etc/passwd)" +ORIG_UID="$(echo "$ORIGPASSWD" | cut -f3 -d:)" +ORIG_GID="$(echo "$ORIGPASSWD" | cut -f4 -d:)" +CONTAINER_USER_HOME="$(echo "$ORIGPASSWD" | cut -f6 -d:)" +CONTAINER_USER_UID="${CONTAINER_USER_UID:=$ORIG_UID}" +CONTAINER_USER_GID="${CONTAINER_USER_GID:=$ORIG_GID}" -if [ "$CONTAINER_USER_UID" != "$ORIG_UID" -o "$CONTAINER_USER_GID" != "$ORIG_GID" ]; then +if [ "$CONTAINER_USER_UID" != "$ORIG_UID" ] || [ "$CONTAINER_USER_GID" != "$ORIG_GID" ]; then groupmod -g "$CONTAINER_USER_GID" "${USERNAME}" usermod -u "$CONTAINER_USER_UID" -g "$CONTAINER_USER_GID" "${USERNAME}" fi -if [ "$(stat -c '%u' "${CONTAINER_USER_HOME}")" != "${CONTAINER_USER_UID}" -o "$(stat -c '%g' "${CONTAINER_USER_HOME}")" != "${CONTAINER_USER_GID}" ]; then +if [ "$(stat -c '%u' "${CONTAINER_USER_HOME}")" != "${CONTAINER_USER_UID}" ] || [ "$(stat -c '%g' "${CONTAINER_USER_HOME}")" != "${CONTAINER_USER_GID}" ]; then chown "${CONTAINER_USER_UID}":"${CONTAINER_USER_GID}" "${CONTAINER_USER_HOME}" chown -R "${CONTAINER_USER_UID}":"${CONTAINER_USER_GID}" "${CONTAINER_USER_HOME}"/.* if [ -d /usr/local/php ]; then @@ -62,12 +66,17 @@ sed -e "s?^group =.*?group = ${USERNAME}?g" --in-place "${FPMCONF}" sed -e "s?^listen.owner =.*?listen.owner = ${USERNAME}?g" --in-place "${FPMCONF}" sed -e "s?^listen.group =.*?listen.group = ${USERNAME}?g" --in-place "${FPMCONF}" -echo "[$(date)] Running Composer..." +if [ -f "${TESTS_ROOT_DIR}/composer.json" ]; then + echo "[$(date)] Running Composer..." -# @todo if there is a composer.lock file present, there are chances it might be a leftover from when running the -# container using a different php version. We should then back it up / do some symlink magic to make sure that -# it matches the current php version and a hash of composer.json... -su "${USERNAME}" -c "cd ${TESTS_ROOT_DIR} && composer install" + # @todo if there is a composer.lock file present, there are chances it might be a leftover from when running the + # container using a different php version. We should then back it up / do some symlink magic to make sure that + # it matches the current php version and a hash of composer.json... + su "${USERNAME}" -c "cd ${TESTS_ROOT_DIR} && composer install" +else + # @todo should we exit? + echo "Missing file '${TESTS_ROOT_DIR}/composer.json' - was the container started without the correct mount?" >&2 +fi trap clean_up TERM diff --git a/tests/ci/setup/install_packages.sh b/tests/ci/setup/install_packages.sh index 4e5c55d..1076847 100755 --- a/tests/ci/setup/install_packages.sh +++ b/tests/ci/setup/install_packages.sh @@ -6,6 +6,8 @@ set -e echo "Installing base software packages..." +# @todo make updating of preinstalled sw optional, so that we can have faster builds as part of CI + apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y \ diff --git a/tests/ci/vm.sh b/tests/ci/vm.sh index e0cf30f..1f178df 100755 --- a/tests/ci/vm.sh +++ b/tests/ci/vm.sh @@ -14,6 +14,7 @@ export UBUNTU_VERSION=${UBUNTU_VERSION:-focal} CONTAINER_USER=docker CONTAINER_WORKSPACE_DIR="/home/${CONTAINER_USER}/workspace" ROOT_DIR="$(dirname -- "$(dirname -- "$(dirname -- "$(readlink -f "$0")")")")" +# @todo (low priority) allow passing in a custom prefix for image name, container name IMAGE_NAME=phpxmlrpc:${UBUNTU_VERSION}-${PHP_VERSION} CONTAINER_NAME=phpxmlrpc_${UBUNTU_VERSION}_${PHP_VERSION} @@ -73,8 +74,8 @@ build() { docker run -d \ -p 80:80 -p 443:443 -p 8080:8080 \ --name "${CONTAINER_NAME}" \ - --env CONTAINER_USER_UID=$(id -u) --env CONTAINER_USER_GID=$(id -g) \ - --env TESTS_ROOT_DIR=${CONTAINER_WORKSPACE_DIR} \ + --env "CONTAINER_USER_UID=$(id -u)" --env "CONTAINER_USER_GID=$(id -g)" \ + --env "TESTS_ROOT_DIR=${CONTAINER_WORKSPACE_DIR}" \ --env HTTPSERVER=localhost \ --env HTTPURI=/tests/index.php?demo=server/server.php \ --env HTTPSSERVER=localhost \