1
1
Fork 0

Merge pull request #11679 from Quix0r/rewrites/autotest

Rewrite of autotest.sh
This commit is contained in:
Hypolite Petovan 2022-06-23 12:41:14 -04:00 committed by GitHub
commit dbc1ebbb5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 79 deletions

8
.gitignore vendored
View file

@ -90,3 +90,11 @@ venv/
#ignore avatar picture cache path #ignore avatar picture cache path
/avatar /avatar
#Ignore autotest results
autotest-results.xml
#ignore phpunit result cache
tests/.phpunit.result.cache
#ignore .php_cs (local copy)
.php_cs

View file

@ -15,33 +15,34 @@
# - TEST_SELECTION= ... Specify which tests are used to run (based on the test-labeling) # - TEST_SELECTION= ... Specify which tests are used to run (based on the test-labeling)
# - XDEBUG_CONFIG= ... Set some XDEBUG specific environment settings for development # - XDEBUG_CONFIG= ... Set some XDEBUG specific environment settings for development
DATABASENAME=${MYSQL_DATABASE:-test} DATABASE_NAME=${FRIENDICA_MYSQL_DATABASE:-test}
DATABASEUSER=${MYSQL_USERNAME:-friendica} DATABASE_USER=${FRIENDICA_MYSQL_USERNAME:-friendica}
DATABASEHOST=${MYSQL_HOST:-localhost} DATABASE_HOST=${FRIENDICA_MYSQL_HOST:-localhost}
BASEDIR=$PWD DATABASE_PASSWORD=${FRIENDICA_MYSQL_PASSWORD:-friendica}
BASEDIR=${PWD}
DBCONFIGS="mysql mariadb" DBCONFIGS="mysql mariadb"
TESTS="REDIS MEMCACHE MEMCACHED APCU NODB" TESTS="REDIS MEMCACHE MEMCACHED APCU NODB"
export MYSQL_DATABASE="$DATABASENAME" export MYSQL_DATABASE="${DATABASE_NAME}"
export MYSQL_USERNAME="$DATABASEUSER" export MYSQL_USERNAME="${DATABASE_USER}"
export MYSQL_PASSWORD="friendica" export MYSQL_PASSWORD="${DATABASE_PASSWORD}"
if [ -z "$PHP_EXE" ]; then if [ -z "${PHP_EXE}" ]; then
PHP_EXE=php PHP_EXE=php
fi fi
PHP=$(which "$PHP_EXE") PHP=$(which "${PHP_EXE}")
# Use the Friendica internal composer # Use the Friendica internal composer
COMPOSER="$BASEDIR/bin/composer.phar" COMPOSER="${BASEDIR}/bin/composer.phar"
set -e set -e
_XDEBUG_CONFIG=$XDEBUG_CONFIG _XDEBUG_CONFIG=${XDEBUG_CONFIG}
unset XDEBUG_CONFIG unset XDEBUG_CONFIG
function show_syntax() { function show_syntax() {
echo -e "Syntax: ./autotest.sh [dbconfigname] [testfile]\n" >&2 echo -e "Syntax: ./autotest.sh [dbconfigname] [testfile]\n" >&2
echo -e "\t\"dbconfigname\" can be one of: $DBCONFIGS" >&2 echo -e "\t\"dbconfigname\" can be one of: ${DBCONFIGS}" >&2
echo -e "\t\"testfile\" is the name of a test file, for example lib/template.php" >&2 echo -e "\t\"testfile\" is the name of a test file, for example lib/template.php" >&2
echo -e "\nDatabase environment variables:\n" >&2 echo -e "\nDatabase environment variables:\n" >&2
echo -e "\t\"MYSQL_HOST\" Mysql Hostname (Default: localhost)" >&2 echo -e "\t\"MYSQL_HOST\" Mysql Hostname (Default: localhost)" >&2
@ -57,22 +58,22 @@ function show_syntax() {
echo -e "\nIf no arguments are specified, all tests will be run with all database configs" >&2 echo -e "\nIf no arguments are specified, all tests will be run with all database configs" >&2
} }
if [ -x "$PHP" ]; then if [ -x "${PHP}" ]; then
echo "Using PHP executable $PHP" echo "Using PHP executable ${PHP}"
else else
echo "Could not find PHP executable $PHP_EXE" >&2 echo "Could not find PHP executable ${PHP_EXE}" >&2
exit 3 exit 3
fi fi
echo "Installing depdendencies" echo "Installing depdendencies"
$PHP "$COMPOSER" install ${PHP} "$COMPOSER" install
PHPUNIT="$BASEDIR/vendor/bin/phpunit" PHPUNIT="${BASEDIR}/vendor/bin/phpunit"
if [ -x "$PHPUNIT" ]; then if [ -x "${PHPUNIT}" ]; then
echo "Using PHPUnit executable $PHPUNIT" echo "Using PHPUnit executable ${PHPUNIT}"
else else
echo "Could not find PHPUnit executable after composer $PHPUNIT" >&2 echo "Could not find PHPUnit executable after composer ${PHPUNIT}" >&2
exit 3 exit 3
fi fi
@ -83,8 +84,8 @@ fi
if [ "$1" ]; then if [ "$1" ]; then
FOUND=0 FOUND=0
for DBCONFIG in $DBCONFIGS; do for DBCONFIG in ${DBCONFIGS}; do
if [ "$1" = "$DBCONFIG" ]; then if [ "$1" = "${DBCONFIG}" ]; then
FOUND=1 FOUND=1
break break
fi fi
@ -103,13 +104,13 @@ fi
function cleanup_config() { function cleanup_config() {
if [ -n "$DOCKER_CONTAINER_ID" ]; then if [ -n "${DOCKER_CONTAINER_ID}" ]; then
echo "Kill the docker $DOCKER_CONTAINER_ID" echo "Kill the docker ${DOCKER_CONTAINER_ID}"
docker stop "$DOCKER_CONTAINER_ID" docker stop "${DOCKER_CONTAINER_ID}"
docker rm -f "$DOCKER_CONTAINER_ID" docker rm -f "${DOCKER_CONTAINER_ID}"
fi fi
cd "$BASEDIR" cd "${BASEDIR}"
# Restore existing config # Restore existing config
if [ -f config/local.config-autotest-backup.php ]; then if [ -f config/local.config-autotest-backup.php ]; then
@ -122,77 +123,77 @@ trap cleanup_config EXIT
function execute_tests() { function execute_tests() {
DB=$1 DB=$1
echo "Setup environment for $DB testing ..." echo "Setup environment for ${DB} testing ..."
# back to root folder # back to root folder
cd "$BASEDIR" cd "${BASEDIR}"
# backup current config # backup current config
if [ -f config/local.config.php ]; then if [ -f config/local.config.php ]; then
mv config/local.config.php config/local.config-autotest-backup.php mv config/local.config.php config/local.config-autotest-backup.php
fi fi
if [ -z "$NOINSTALL" ]; then if [ -z "${NOINSTALL}" ]; then
#drop database #drop database
if [ "$DB" == "mysql" ]; then if [ "${DB}" == "mysql" ]; then
if [ -n "$USEDOCKER" ]; then if [ -n "${USEDOCKER}" ]; then
echo "Fire up the mysql docker" echo "Fire up the mysql docker"
DOCKER_CONTAINER_ID=$(docker run \ DOCKER_CONTAINER_ID=$(docker run \
-e MYSQL_ROOT_PASSWORD=friendica \ -e MYSQL_ROOT_PASSWORD=friendica \
-e MYSQL_USER="$DATABASEUSER" \ -e MYSQL_USER="${DATABASE_USER}" \
-e MYSQL_PASSWORD=friendica \ -e MYSQL_PASSWORD=friendica \
-e MYSQL_DATABASE="$DATABASENAME" \ -e MYSQL_DATABASE="${DATABASE_NAME}" \
-d mysql) -d mysql)
DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID") DATABASE_HOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "${DOCKER_CONTAINER_ID}")
else else
if [ -z "$DRONE" ]; then # no need to drop the DB when we are on CI if [ -z "${DRONE}" ]; then # no need to drop the DB when we are on CI
if [ "mysql" != "$(mysql --version | grep -o mysql)" ]; then if [ "mysql" != "$(mysql --version | grep -o mysql)" ]; then
echo "Your mysql binary is not provided by mysql" echo "Your mysql binary is not provided by mysql"
echo "To use the docker container set the USEDOCKER environment variable" echo "To use the docker container set the USEDOCKER environment variable"
exit 3 exit 3
fi fi
mysql -u "$DATABASEUSER" -pfriendica -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true mysql -u "${DATABASE_USER}" -pfriendica -e "DROP DATABASE IF EXISTS ${DATABASE_NAME}" -h ${DATABASE_HOST} || true
mysql -u "$DATABASEUSER" -pfriendica -e "CREATE DATABASE $DATABASENAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" -h $DATABASEHOST mysql -u "${DATABASE_USER}" -pfriendica -e "CREATE DATABASE ${DATABASE_NAME} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" -h ${DATABASE_HOST}
else else
DATABASEHOST=mysql DATABASE_HOST=mysql
fi fi
fi fi
echo "Waiting for MySQL $DATABASEHOST initialization..." echo "Waiting for MySQL ${DATABASE_HOST} initialization..."
if ! bin/wait-for-connection $DATABASEHOST 3306 300; then if ! bin/wait-for-connection ${DATABASE_HOST} 3306 300; then
echo "[ERROR] Waited 300 seconds, no response" >&2 echo "[ERROR] Waited 300 seconds, no response" >&2
exit 1 exit 1
fi fi
echo "MySQL is up." echo "MySQL is up."
fi fi
if [ "$DB" == "mariadb" ]; then if [ "${DB}" == "mariadb" ]; then
if [ -n "$USEDOCKER" ]; then if [ -n "${USEDOCKER}" ]; then
echo "Fire up the mariadb docker" echo "Fire up the mariadb docker"
DOCKER_CONTAINER_ID=$(docker run \ DOCKER_CONTAINER_ID=$(docker run \
-e MYSQL_ROOT_PASSWORD=friendica \ -e MYSQL_ROOT_PASSWORD=friendica \
-e MYSQL_USER="$DATABASEUSER" \ -e MYSQL_USER="${DATABASE_USER}" \
-e MYSQL_PASSWORD=friendica \ -e MYSQL_PASSWORD=friendica \
-e MYSQL_DATABASE="$DATABASENAME" \ -e MYSQL_DATABASE="${DATABASE_NAME}" \
-d mariadb) -d mariadb)
DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID") DATABASE_HOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "${DOCKER_CONTAINER_ID}")
else else
if [ -z "$DRONE" ]; then # no need to drop the DB when we are on CI if [ -z "${DRONE}" ]; then # no need to drop the DB when we are on CI
if [ "MariaDB" != "$(mysql --version | grep -o MariaDB)" ]; then if [ "MariaDB" != "$(mysql --version | grep -o MariaDB)" ]; then
echo "Your mysql binary is not provided by mysql" echo "Your mysql binary is not provided by mysql"
echo "To use the docker container set the USEDOCKER environment variable" echo "To use the docker container set the USEDOCKER environment variable"
exit 3 exit 3
fi fi
mysql -u "$DATABASEUSER" -pfriendica -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true mysql -u "${DATABASE_USER}" -pfriendica -e "DROP DATABASE IF EXISTS ${DATABASE_NAME}" -h ${DATABASE_HOST} || true
mysql -u "$DATABASEUSER" -pfriendica -e "CREATE DATABASE $DATABASENAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" -h $DATABASEHOST mysql -u "${DATABASE_USER}" -pfriendica -e "CREATE DATABASE ${DATABASE_NAME} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" -h ${DATABASE_HOST}
else else
DATABASEHOST=mariadb DATABASE_HOST=mariadb
fi fi
fi fi
echo "Waiting for MariaDB $DATABASEHOST initialization..." echo "Waiting for MariaDB ${DATABASE_HOST} initialization..."
if ! bin/wait-for-connection $DATABASEHOST 3306 300; then if ! bin/wait-for-connection ${DATABASE_HOST} 3306 300; then
echo "[ERROR] Waited 300 seconds, no response" >&2 echo "[ERROR] Waited 300 seconds, no response" >&2
exit 1 exit 1
fi fi
@ -200,28 +201,28 @@ function execute_tests() {
echo "MariaDB is up." echo "MariaDB is up."
fi fi
if [ -n "$USEDOCKER" ]; then if [ -n "${USEDOCKER}" ]; then
echo "Initialize database..." echo "Initialize database..."
docker exec $DOCKER_CONTAINER_ID mysql -u root -pfriendica -e 'CREATE DATABASE IF NOT EXISTS $DATABASENAME;' docker exec ${DOCKER_CONTAINER_ID} mysql -u root -pfriendica -e "CREATE DATABASE IF NOT EXISTS ${DATABASE_NAME};"
fi fi
export MYSQL_HOST="$DATABASEHOST" export MYSQL_HOST="${DATABASE_HOST}"
#call installer #call installer
echo "Installing Friendica..." echo "Installing Friendica..."
"$PHP" ./bin/console.php autoinstall --dbuser="$DATABASEUSER" --dbpass=friendica --dbdata="$DATABASENAME" --dbhost="$DATABASEHOST" --url=https://friendica.local --admin=admin@friendica.local "${PHP}" ./bin/console.php autoinstall --dbuser="${DATABASE_USER}" --dbpass=friendica --dbdata="${DATABASE_NAME}" --dbhost="${DATABASE_HOST}" --url=https://friendica.local --admin=admin@friendica.local
fi fi
#test execution #test execution
echo "Testing..." echo "Testing..."
rm -fr "coverage-html" rm -fr "coverage-html"
mkdir "coverage-html" mkdir "coverage-html"
if [[ "$_XDEBUG_CONFIG" ]]; then if [[ "${_XDEBUG_CONFIG}" ]]; then
export XDEBUG_CONFIG=$_XDEBUG_CONFIG export XDEBUG_CONFIG=${_XDEBUG_CONFIG}
fi fi
COVER='' COVER=''
if [ -z "$NOCOVERAGE" ]; then if [ -z "${NOCOVERAGE}" ]; then
COVER="--coverage-clover tests/autotest-clover.xml" COVER="--coverage-clover tests/autotest-clover.xml"
else else
echo "No coverage" echo "No coverage"
@ -229,51 +230,51 @@ function execute_tests() {
# per default, there is no cache installed # per default, there is no cache installed
GROUP='--exclude-group REDIS,MEMCACHE,MEMCACHED,APCU' GROUP='--exclude-group REDIS,MEMCACHE,MEMCACHED,APCU'
if [ "$TEST_SELECTION" == "REDIS" ]; then if [ "${TEST_SELECTION}" == "REDIS" ]; then
GROUP="--group REDIS" GROUP="--group REDIS"
fi fi
if [ "$TEST_SELECTION" == "MEMCACHE" ]; then if [ "${TEST_SELECTION}" == "MEMCACHE" ]; then
GROUP="--group MEMCACHE" GROUP="--group MEMCACHE"
fi fi
if [ "$TEST_SELECTION" == "MEMCACHED" ]; then if [ "${TEST_SELECTION}" == "MEMCACHED" ]; then
GROUP="--group MEMCACHED" GROUP="--group MEMCACHED"
fi fi
if [ "$TEST_SELECTION" == "APCU" ]; then if [ "${TEST_SELECTION}" == "APCU" ]; then
GROUP="--group APCU" GROUP="--group APCU"
fi fi
if [ "$TEST_SELECTION" == "NODB" ]; then if [ "${TEST_SELECTION}" == "NODB" ]; then
GROUP="--exclude-group DB,SLOWDB" GROUP="--exclude-group DB,SLOWDB"
fi fi
INPUT="$BASEDIR/tests" INPUT="${BASEDIR}/tests"
if [ -n "$2" ]; then if [ -n "$2" ]; then
INPUT="$INPUT/$2" INPUT="${INPUT}/$2"
fi fi
echo "${PHPUNIT[@]}" --configuration tests/phpunit.xml $GROUP $COVER --log-junit "autotest-results.xml" "$INPUT" "$3" echo "${PHPUNIT[@]}" --configuration tests/phpunit.xml ${GROUP} ${COVER} --log-junit "autotest-results.xml" "${INPUT}" "$3"
"${PHPUNIT[@]}" --configuration tests/phpunit.xml $GROUP $COVER --log-junit "autotest-results.xml" "$INPUT" "$3" "${PHPUNIT[@]}" --configuration tests/phpunit.xml ${GROUP} ${COVER} --log-junit "autotest-results.xml" "${INPUT}" "$3"
RESULT=$? RESULT=$?
if [ -n "$DOCKER_CONTAINER_ID" ]; then if [ -n "${DOCKER_CONTAINER_ID}" ]; then
echo "Kill the docker $DOCKER_CONTAINER_ID" echo "Kill the docker ${DOCKER_CONTAINER_ID}"
docker stop $DOCKER_CONTAINER_ID docker stop ${DOCKER_CONTAINER_ID}
docker rm -f $DOCKER_CONTAINER_ID docker rm -f ${DOCKER_CONTAINER_ID}
unset $DOCKER_CONTAINER_ID unset ${DOCKER_CONTAINER_ID}
fi fi
} }
# #
# Start the test execution # Start the test execution
# #
if [ -z "$1" ] && [ -n "$TEST_SELECTION" ]; then if [ -z "$1" ] && [ -n "${TEST_SELECTION}" ]; then
# run all known database configs # run all known database configs
for DBCONFIG in $DBCONFIGS; do for DBCONFIG in ${DBCONFIGS}; do
execute_tests "$DBCONFIG" execute_tests "${DBCONFIG}"
done done
else else
FILENAME="$2" FILENAME="$2"
if [ -n "$2" ] && [ ! -f "tests/$FILENAME" ] && [ "${FILENAME:0:2}" != "--" ]; then if [ -n "$2" ] && [ ! -f "tests/${FILENAME}" ] && [ "${FILENAME:0:2}" != "--" ]; then
FILENAME="../$FILENAME" FILENAME="../${FILENAME}"
fi fi
execute_tests "$1" "$FILENAME" "$3" execute_tests "$1" "${FILENAME}" "$3"
fi fi