From 0e16be827395670d997a3fd5201e369addb4d6b8 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 8 Jan 2018 14:54:10 -0500 Subject: [PATCH] =?UTF-8?q?tests:=20Run=20compose=20tests=20in=20parallel?= =?UTF-8?q?=20=E2=88=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Over a year later, the "opening the host rpmdb" bug is fixed, so we can do composes in parallel ∥, hooray! I'm dusting this off since we were running into CI (PAPR) timeouts when I was adding more to the compose tests. Closes: #545 Approved by: jlebon --- .papr.yml | 2 +- tests/compose | 67 +++++++++++++++++++++------------------------------ 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/.papr.yml b/.papr.yml index 59622c94..0354e2cf 100644 --- a/.papr.yml +++ b/.papr.yml @@ -107,7 +107,7 @@ tests: "./ci/build.sh && make install && ./tests/compose" artifacts: - - compose.log + - test-compose-logs --- diff --git a/tests/compose b/tests/compose index 70235c0f..9701b012 100755 --- a/tests/compose +++ b/tests/compose @@ -4,13 +4,14 @@ set -euo pipefail dn=$(cd $(dirname $0) && pwd) export topsrcdir=$(cd $dn/.. && pwd) +. ${dn}/common/libtest-core.sh . ${dn}/common/libcomposetest.sh # avoid refetching yum metadata everytime export RPMOSTREE_USE_CACHED_METADATA=1 -LOG=${LOG:-compose.log} -date > ${LOG} +LOGDIR=${LOGDIR:-$(pwd)/test-compose-logs} +mkdir -p ${LOGDIR} colour_print() { colour=$1; shift @@ -40,14 +41,14 @@ datadir_owner=$(stat -c '%u' ${test_compose_datadir}) test ${uid} = ${datadir_owner} # Create a consistent cache of the RPMs -echo "Preparing compose tests..." | tee -a ${LOG} +echo "Preparing compose tests..." tmp_repo=${test_compose_datadir}/tmp-repo if test -z "${RPMOSTREE_COMPOSE_CACHEONLY:-}"; then mkdir -p ${test_compose_datadir}/cache setup_rpmmd_repos ${dn}/composedata ostree --repo=${tmp_repo} init --mode=bare-user # We use rpm-ostree in dry-run --cachedir mode - rpm-ostree compose --repo=${tmp_repo} tree --download-only --cachedir=${test_compose_datadir}/cache ${dn}/composedata/fedora-base.json &>> ${LOG} + rpm-ostree compose --repo=${tmp_repo} tree --download-only --cachedir=${test_compose_datadir}/cache ${dn}/composedata/fedora-base.json (cd ${test_compose_datadir}/cache && createrepo_c .) fi rm ${tmp_repo} -rf @@ -56,46 +57,34 @@ total=0 pass=0 fail=0 skip=0 -for tf in $(find ${dn}/compose-tests -name 'test-*.sh' | sort); do - - if [ -n "${TESTS+ }" ]; then +all_tests="$(cd ${dn}/compose-tests && ls test-*.sh | sort)" +tests="" +if [ -n "${TESTS+ }" ]; then + for tf in ${all_tests}; do tfbn=$(basename "$tf" .sh) tfbn=" ${tfbn#test-} " if [[ " $TESTS " != *$tfbn* ]]; then + echo "Skipping: ${tf}" continue fi - fi + tests="${tests} ${tf}" + done +else + tests="${all_tests}" +fi - let "total += 1" +if test -z "${tests}"; then + fatal "error: No tests match ${TESTS}" +fi - bn=$(basename ${tf}) - printf "Running $bn...\n" - printf "\n\n===== ${bn} =====\n\n" >> ${LOG} - - # do some dirty piping to get some instant feedback and help debugging - if ${tf} |& tee -a ${LOG} \ - | grep -e '^ok ' --line-buffered \ - | xargs -d '\n' -n 1 echo " "; then - pass_print "PASS: $bn" - echo "PASS" >> ${LOG} - let "pass += 1" - else - if test $? = 77; then - skip_print "SKIP: $bn" - echo "SKIP" >> ${LOG} - let "skip += 1" - else - fail_print "FAIL: $bn" - echo "FAIL" >> ${LOG} - let "fail += 1" - if test -n "${RPMOSTREE_COMPOSE_FASTFAIL:-}"; then - break; - fi - fi - fi +echo "Compose tests starting: $(date)" +echo "Executing: ${tests}" +echo "Writing logs to ${LOGDIR}" +(for tf in ${tests}; do echo $tf; done) | \ + parallel --halt soon,fail=1 --results ${LOGDIR} ${dn}/compose-tests/{} |& tail +echo "$(date): All tests passed" +# Help out S3 to have the right MIME type +for x in ${LOGDIR}/1/*.sh; do + mv ${x}/stdout{,.txt} + mv ${x}/stderr{,.txt} done - -[ ${fail} -eq 0 ] && printer=pass || printer=fail -${printer}_print "TOTAL: $total PASS: $pass SKIP: $skip FAIL: $fail" -echo "See ${LOG} for more information." -[ ${fail} -eq 0 ]