Skip to content

Commit

Permalink
small improvements to test code and test container build
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Apr 16, 2024
1 parent f164fbd commit eb12710
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
9 changes: 5 additions & 4 deletions tests/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
35 changes: 22 additions & 13 deletions tests/ci/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions tests/ci/setup/install_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 3 additions & 2 deletions tests/ci/vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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 \
Expand Down

0 comments on commit eb12710

Please sign in to comment.