From 48d2637e98a6f2272dd13e3406060f2bef1c48f1 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 8 May 2017 13:37:50 -0400 Subject: [PATCH] tests: Migrate test-pull-many.sh to installed on FAH `test-pull-many.sh` is was just too slow to be a unit test. Generating a bunch of files via shell is slow, the delta generation is slow, etc. Every developer doesn't need to run it every time. Somewhat address this by converting it into our installed test framework, which moves it out of the developer fast paths. Another advantage to this is that we can simply reuse the FAH tree content rather than synthesizing new bits each time. Closes: #840 Approved by: jlebon --- Makefile-tests.am | 1 - tests/installed/itest-pull.sh | 27 ++++++++++++++++++ tests/installed/libinsttest.sh | 43 ++++++++++++++++++++++++++++ tests/test-pull-many.sh | 52 ---------------------------------- 4 files changed, 70 insertions(+), 53 deletions(-) create mode 100755 tests/installed/itest-pull.sh delete mode 100755 tests/test-pull-many.sh diff --git a/Makefile-tests.am b/Makefile-tests.am index 14e30b46..335ba9b7 100644 --- a/Makefile-tests.am +++ b/Makefile-tests.am @@ -77,7 +77,6 @@ _installed_or_uninstalled_test_scripts = \ tests/test-pull-resume.sh \ tests/test-pull-repeated.sh \ tests/test-pull-untrusted.sh \ - tests/test-pull-many.sh \ tests/test-pull-override-url.sh \ tests/test-local-pull.sh \ tests/test-local-pull-depth.sh \ diff --git a/tests/installed/itest-pull.sh b/tests/installed/itest-pull.sh new file mode 100755 index 00000000..e3125f4c --- /dev/null +++ b/tests/installed/itest-pull.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Using the host ostree, test HTTP pulls + +set -xeuo pipefail + +dn=$(dirname $0) +. ${dn}/libinsttest.sh + +test_tmpdir=$(prepare_tmpdir) +trap _tmpdir_cleanup EXIT + +# Take the host's ostree, and make it archive +cd /var/srv +rm repo bare-repo -rf +mkdir repo +ostree --repo=repo init --mode=archive +echo -e '[archive]\nzlib-level=1\n' >> repo/config +host_nonremoteref=$(echo ${host_refspec} | sed 's,[^:]*:,,') +ostree --repo=repo pull-local /ostree/repo ${host_commit} +ostree --repo=repo refs ${host_commit} --create=${host_nonremoteref} + +run_tmp_webserver $(pwd)/repo +# Now test pulling via HTTP (no deltas) to a new bare-user repo +ostree --repo=bare-repo init --mode=bare-user +ostree --repo=bare-repo remote add origin --set=gpg-verify=false $(cat ${test_tmpdir}/httpd-address) +ostree --repo=bare-repo pull --disable-static-deltas origin ${host_nonremoteref} diff --git a/tests/installed/libinsttest.sh b/tests/installed/libinsttest.sh index 4f72b651..759c95f2 100644 --- a/tests/installed/libinsttest.sh +++ b/tests/installed/libinsttest.sh @@ -20,6 +20,49 @@ dn=$(dirname $0) . ${dn}/libtest-core.sh +# Copy of bits from tap-test +test_tmpdir= +function _tmpdir_cleanup () { + if test -n "${test_tmpdir}" && test -f ${test_tmpdir}/.testtmp; then + rm "${test_tmpdir}" -rf + fi +} +prepare_tmpdir() { + test_tmpdir=$(mktemp -d) + touch ${test_tmpdir}/.testtmp + cd ${test_tmpdir} + echo ${test_tmpdir} +} + +# This is copied from flatpak/flatpak/tests/test-webserver.sh +run_tmp_webserver() { + dir=$1 + + test -n ${test_tmpdir} + + cd ${dir} + env PYTHONUNBUFFERED=1 setsid python -m SimpleHTTPServer 0 &>${test_tmpdir}/httpd-output & + cd - + child_pid=$! + + for x in $(seq 50); do + # Snapshot the output + cp ${test_tmpdir}/httpd-output{,.tmp} + # If it's non-empty, see whether it matches our regexp + if test -s ${test_tmpdir}/httpd-output.tmp; then + sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\) \.\.\.,\1,' < ${test_tmpdir}/httpd-output.tmp > ${test_tmpdir}/httpd-port + if ! cmp ${test_tmpdir}/httpd-output.tmp ${test_tmpdir}/httpd-port 1>/dev/null; then + # If so, we've successfully extracted the port + break + fi + fi + sleep 0.1 + done + port=$(cat ${test_tmpdir}/httpd-port) + echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address + echo "$child_pid" > ${test_tmpdir}/httpd-pid +} + # Determine our origin refspec - we'll use this as a test base rpmostree=$(which rpm-ostree 2>/dev/null) if test -z "${rpmostree}"; then diff --git a/tests/test-pull-many.sh b/tests/test-pull-many.sh deleted file mode 100755 index 73245a6b..00000000 --- a/tests/test-pull-many.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2017 Colin Walters -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -set -euo pipefail - -. $(dirname $0)/libtest.sh - -setup_exampleos_repo - -echo '1..3' - -cd ${test_tmpdir} -set -x - -echo "$(date): Pulling content..." -rev=$(${CMD_PREFIX} ostree --repo=ostree-srv/exampleos/repo rev-parse ${REF}) -${CMD_PREFIX} ostree --repo=repo pull --disable-static-deltas origin ${REF} -${CMD_PREFIX} ostree --repo=repo fsck -assert_streq ${rev} $(${CMD_PREFIX} ostree --repo=repo rev-parse ${REF}) - -echo "ok without deltas" - -previous=$(${CMD_PREFIX} ostree --repo=repo rev-parse ${rev}^) -rm repo/refs/{heads,remotes}/* -rf -${CMD_PREFIX} ostree --repo=repo prune --refs-only -${CMD_PREFIX} ostree --repo=repo pull origin ${REF}@${previous} -${CMD_PREFIX} ostree --repo=repo pull --dry-run --require-static-deltas origin ${REF} > output.txt -assert_file_has_content output.txt 'Delta update: 0/1 parts, 0 bytes/1.[012] MB, 1.[345] MB total uncompressed' - -echo "ok delta dry-run" - -${CMD_PREFIX} ostree --repo=repo pull --require-static-deltas origin ${REF} -assert_streq $(${CMD_PREFIX} ostree --repo=repo rev-parse ${REF}) ${rev} -${CMD_PREFIX} ostree --repo=repo fsck - -echo "ok"