From 12e4c8dab109fe493ebf65e1625a8002a32f37f5 Mon Sep 17 00:00:00 2001
From: Nicolas KAROLAK <nicolas@karolak.fr>
Date: Wed, 24 Apr 2019 16:53:01 +0200
Subject: [PATCH] check apt lock state

---
 tests/test_apt.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tests/test_apt.sh b/tests/test_apt.sh
index 2cb193f2..8c3d1582 100755
--- a/tests/test_apt.sh
+++ b/tests/test_apt.sh
@@ -8,6 +8,19 @@ DEBIAN_FRONTEND=noninteractive
 
 echo "Testing apt-get install."
 
+lock_timeout=120
+lock_counter=0
+tput sc
+while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
+    sleep 1 && echo $lock_counter && (( lock_counter++ ))
+    tput rc
+    if (( $lock_counter > $lock_timeout )); then
+        echo "APT is reported as locked for more than $lock_timeout seconds now..."
+        echo "Either a big upgrade is running or it is hung, please take a look"
+        exit 1
+    fi
+done
+
 echo "Clean repository."
 apt-get clean
 
-- 
GitLab