From 640602b53ec3a387aef776d6a727118e1784f6d7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 7 Jan 2018 11:35:34 +0000 Subject: [PATCH] test suite: gnupg: Run with a lock held This is also an attempt to reduce the impact of the gnupg races. Signed-off-by: Ian Jackson --- tests/setup/gnupg | 5 ++++- tests/tstunt/gpg | 32 +++----------------------------- tests/tstunt/gpg-locked | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 30 deletions(-) create mode 100755 tests/tstunt/gpg-locked diff --git a/tests/setup/gnupg b/tests/setup/gnupg index 9b4d0990..c88d40be 100755 --- a/tests/setup/gnupg +++ b/tests/setup/gnupg @@ -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 <&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 index 00000000..892b9c8c --- /dev/null +++ b/tests/tstunt/gpg-locked @@ -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 -- 2.30.2