[PATCH 1 of 2 V3] debuglocks: add tests (and fix typo in early return)

Paul Morelle paul.morelle at octobus.net
Sun Nov 19 22:54:50 EST 2017


# HG changeset patch
# User Paul Morelle <paul.morelle at octobus.net>
# Date 1510497259 -3600
#      Sun Nov 12 15:34:19 2017 +0100
# Node ID 9b602162e10949a80e90d9732bb654b430e0b22a
# Parent  602c168c0207c443ac61f7a7c727b31cfb0b86ad
# EXP-Topic debugsetlocks
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 9b602162e109
debuglocks: add tests (and fix typo in early return)

diff -r 602c168c0207 -r 9b602162e109 mercurial/debugcommands.py
--- a/mercurial/debugcommands.py	Tue Nov 07 13:18:49 2017 -0500
+++ b/mercurial/debugcommands.py	Sun Nov 12 15:34:19 2017 +0100
@@ -1200,7 +1200,7 @@
         repo.svfs.unlink('lock')
     if opts.get(r'force_wlock'):
         repo.vfs.unlink('wlock')
-    if opts.get(r'force_lock') or opts.get(r'force_lock'):
+    if opts.get(r'force_lock') or opts.get(r'force_wlock'):
         return 0
 
     now = time.time()
diff -r 602c168c0207 -r 9b602162e109 tests/test-debugcommands.t
--- a/tests/test-debugcommands.t	Tue Nov 07 13:18:49 2017 -0500
+++ b/tests/test-debugcommands.t	Sun Nov 12 15:34:19 2017 +0100
@@ -111,6 +111,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


More information about the Mercurial-devel mailing list