chiark / gitweb /
test suite: gnupg: Run with a lock held
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Jan 2018 11:35:34 +0000 (11:35 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 7 Jan 2018 16:18:53 +0000 (16:18 +0000)
This is also an attempt to reduce the impact of the gnupg races.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
tests/setup/gnupg
tests/tstunt/gpg
tests/tstunt/gpg-locked [new file with mode: 0755]

index 9b4d09908e107cb73cfa8e40f13e4f8837c793a4..c88d40be47f7fce7a5cacec963d1b63e9bbf2625 100755 (executable)
@@ -6,8 +6,11 @@ mkdir -p $tmp/gnupg
 cp $troot/gnupg/* $tmp/gnupg
 chmod go-rw $tmp/gnupg/*
 
+export DGIT_TEST_GNUPG_GLOBAL_LOCK=$tmp/gnupg/dgit-test-global-lock
+
 setup='
        export GNUPGHOME=$tmp/gnupg
+       export DGIT_TEST_GNUPG_GLOBAL_LOCK
 
        cat >$tmp/gnupg/gpg-agent.conf <<END
        log-file $tmp/gnupg/AGENT.log
@@ -24,6 +27,6 @@ eval "$setup"
 
 gpg --list-secret
 
-t-setup-done '' 'gnupg' "$setup"
+t-setup-done 'DGIT_TEST_GNUPG_GLOBAL_LOCK' 'gnupg' "$setup"
 
 t-ok
index 892b9c8cf446b255a221276463553c88fc83a0f7..679a6b8e10826cba63b7bd57d5ee34d69fab877c 100755 (executable)
@@ -1,32 +1,6 @@
 #!/bin/sh
 set -e
 
-for attempt in '' ' ' exec; do
-
-set +e
-$attempt                                               \
-$DGIT_TEST_REAL_GPG                                    \
-       --agent-program=$DGIT_STUNT_AGENT               \
-       "$@"
-rc=$?
-set -e
-
-if [ $rc != 2 ]; then exit $rc; fi
-
-echo >&2 "WARNING - GNUPG FAILED $rc - STUNT GNUPG $attempt $*"
-
-sh -ec '
-       if [ "x$DGIT_GNUPG_STUNT_ERRLOG" != x ]; then
-               exec >"$DGIT_GNUPG_STUNT_ERRLOG"
-       else
-               exec 2>/dev/null
-       fi
-       exec >/dev/tty
-       printf "%s\n" "$*"
-' x "GNUPG WRAPPER - TROUBLE - $HOME $GNUPGHOME - FAILED $rc $attempt $*"
-
-sleep 10
-
-done
-
-exit 127
+exec \
+with-lock-ex -w "$DGIT_TEST_GNUPG_GLOBAL_LOCK" \
+       $tmp "$DGIT_TEST_TROOT"/tstunt/gpg-locked "$@"
diff --git a/tests/tstunt/gpg-locked b/tests/tstunt/gpg-locked
new file mode 100755 (executable)
index 0000000..892b9c8
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/sh
+set -e
+
+for attempt in '' ' ' exec; do
+
+set +e
+$attempt                                               \
+$DGIT_TEST_REAL_GPG                                    \
+       --agent-program=$DGIT_STUNT_AGENT               \
+       "$@"
+rc=$?
+set -e
+
+if [ $rc != 2 ]; then exit $rc; fi
+
+echo >&2 "WARNING - GNUPG FAILED $rc - STUNT GNUPG $attempt $*"
+
+sh -ec '
+       if [ "x$DGIT_GNUPG_STUNT_ERRLOG" != x ]; then
+               exec >"$DGIT_GNUPG_STUNT_ERRLOG"
+       else
+               exec 2>/dev/null
+       fi
+       exec >/dev/tty
+       printf "%s\n" "$*"
+' x "GNUPG WRAPPER - TROUBLE - $HOME $GNUPGHOME - FAILED $rc $attempt $*"
+
+sleep 10
+
+done
+
+exit 127