tests/test-debugcommands.t
changeset 35394 a43b2dd95e4f
parent 35259 ad5f2b923b0d
child 35395 12055fb3ba30
--- a/tests/test-debugcommands.t	Sun Dec 10 22:50:57 2017 -0500
+++ b/tests/test-debugcommands.t	Sun Nov 12 15:34:19 2017 +0100
@@ -145,6 +145,122 @@
       7     6    -1   ???   ???        ???  ???  ???    0     ???      ????           ?     1        2 (glob)
       8     7    -1   ???   ???        ???  ???  ???    0     ???      ????           ?     1        3 (glob)
 
+Test debuglocks command:
+
+  $ hg debuglocks
+  lock:  free
+  wlock: free
+
+* Test setting the lock
+
+waitlock <file> will wait for file to be created. If it isn't in a reasonable
+amount of time, displays error message and returns 1
+  $ waitlock() {
+  >     start=`date +%s`
+  >     timeout=1
+  >     while [ \( ! -f $1 \) -a \( ! -L $1 \) ]; do
+  >         now=`date +%s`
+  >         if [ "`expr $now - $start`" -gt $timeout ]; then
+  >             echo "timeout: $1 was not created in $timeout seconds"
+  >             return 1
+  >         fi
+  >         sleep 0.1
+  >     done
+  > }
+dolock [wlock] [lock] will set the locks until interrupted
+  $ dolock() {
+  >     declare -A options
+  >     options=([${1:-nolock}]=1 [${2:-nowlock}]=1)
+  >     python <<EOF
+  > from mercurial import hg, ui as uimod
+  > import os
+  > import time
+  > 
+  > repo = hg.repository(uimod.ui.load(), path='.')
+  > `[ -n "${options["wlock"]}" ] && echo "with repo.wlock(False):" || echo "if True:"`
+  >     `[ -n "${options["lock"]}" ] && echo "with repo.lock(False):" || echo "if True:"`
+  >         while not os.path.exists('.hg/unlock'):
+  >             time.sleep(0.1)
+  > os.unlink('.hg/unlock')
+  > EOF
+  > }
+
+  $ dolock lock &
+  $ waitlock .hg/store/lock
+
+  $ hg debuglocks
+  lock:  user *, process * (*s) (glob)
+  wlock: free
+  [1]
+  $ touch .hg/unlock
+  $ wait
+
+* Test setting the wlock
+
+  $ dolock wlock &
+  $ waitlock .hg/wlock
+
+  $ hg debuglocks
+  lock:  free
+  wlock: user *, process * (*s) (glob)
+  [1]
+  $ touch .hg/unlock
+  $ wait
+
+* Test setting both locks
+
+  $ dolock wlock lock &
+  $ waitlock .hg/wlock && waitlock .hg/store/lock
+
+  $ hg debuglocks
+  lock:  user *, process * (*s) (glob)
+  wlock: user *, process * (*s) (glob)
+  [2]
+  $ touch .hg/unlock
+  $ wait
+
+  $ hg debuglocks
+  lock:  free
+  wlock: free
+
+* Test forcing the lock
+
+  $ dolock lock &
+  $ waitlock .hg/store/lock
+
+  $ hg debuglocks
+  lock:  user *, process * (*s) (glob)
+  wlock: free
+  [1]
+
+  $ hg debuglocks -L
+
+  $ hg debuglocks
+  lock:  free
+  wlock: free
+
+  $ touch .hg/unlock
+  $ wait
+
+* Test forcing the wlock
+
+  $ dolock wlock &
+  $ waitlock .hg/wlock
+
+  $ hg debuglocks
+  lock:  free
+  wlock: user *, process * (*s) (glob)
+  [1]
+
+  $ hg debuglocks -W
+
+  $ hg debuglocks
+  lock:  free
+  wlock: free
+
+  $ touch .hg/unlock
+  $ wait
+
 Test WdirUnsupported exception
 
   $ hg debugdata -c ffffffffffffffffffffffffffffffffffffffff