From 2991fa41e4c97eea8b3707834c44ad299711d5a5 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 25 May 2020 22:48:01 +0200 Subject: [PATCH] test: create public images by default Let's create new images public by default and then symlink/copy them into the respective private directories afterwards, not the other way around. This should fix a nasty race condition in parallel runs where one tests attempts to copy the backing public image at the same moment another test is already modifying it. --- test/test-functions | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/test-functions b/test/test-functions index f5a798b4b8..e4d690a4e9 100644 --- a/test/test-functions +++ b/test/test-functions @@ -678,6 +678,7 @@ cleanup_loopdev() { if [ -n "${LOOPDEV}" ]; then ddebug "losetup -d $LOOPDEV" losetup -d "${LOOPDEV}" + unset LOOPDEV fi } @@ -698,8 +699,7 @@ create_empty_image() { rm -f "$IMAGE_PRIVATE" "$IMAGE_PUBLIC" # Create the blank file to use as a root filesystem - truncate -s "${_size}M" "$IMAGE_PRIVATE" - ln -vs "$(realpath $IMAGE_PRIVATE)" "$IMAGE_PUBLIC" + truncate -s "${_size}M" "$IMAGE_PUBLIC" LOOPDEV=$(losetup --show -P -f "$IMAGE_PUBLIC") [ -b "$LOOPDEV" ] || return 1 @@ -2005,16 +2005,26 @@ test_setup() { if [ -e "$IMAGE_PRIVATE" ]; then echo "Reusing existing image $IMAGE_PRIVATE → $(realpath $IMAGE_PRIVATE)" mount_initdir - elif [ -e "$IMAGE_PUBLIC" ]; then + else + if [ ! -e "$IMAGE_PUBLIC" ]; then + # Create the backing public image, but then completely unmount + # it and drop the loopback device responsible for it, since we're + # going to symlink/copy the image and mount it again from + # elsewhere. + test_create_image + test_setup_cleanup + umount_loopback + cleanup_loopdev + fi + echo "Reusing existing cached image $IMAGE_PUBLIC → $(realpath $IMAGE_PUBLIC)" if [ ${TEST_PARALLELIZE} -ne 0 ]; then cp -v "$(realpath $IMAGE_PUBLIC)" "$IMAGE_PRIVATE" else ln -sv "$(realpath $IMAGE_PUBLIC)" "$IMAGE_PRIVATE" fi + mount_initdir - else - test_create_image fi setup_nspawn_root