Patchwork [1,of,2,V4] debuglocks: add tests (and fix typo in early return)

login
register
mail settings
Submitter Paul Morelle
Date Dec. 13, 2017, 12:58 a.m.
Message ID <9beb49c91570014c034c.1513126685@taranis.localdomain>
Download mbox | patch
Permalink /patch/26257/
State Accepted
Headers show

Comments

Paul Morelle - Dec. 13, 2017, 12:58 a.m.
# HG changeset patch
# User Paul Morelle <paul.morelle@octobus.net>
# Date 1510497259 -3600
#      Sun Nov 12 15:34:19 2017 +0100
# Node ID 9beb49c91570014c034c3eaad9ce0a7a37e4c931
# Parent  37d923cdeba923f4964befcc3d0789362a433a35
# EXP-Topic debugsetlocks
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 9beb49c91570
debuglocks: add tests (and fix typo in early return)
Yuya Nishihara - Dec. 13, 2017, 12:24 p.m.
On Wed, 13 Dec 2017 01:58:05 +0100, Paul Morelle wrote:
> # HG changeset patch
> # User Paul Morelle <paul.morelle@octobus.net>
> # Date 1510497259 -3600
> #      Sun Nov 12 15:34:19 2017 +0100
> # Node ID 9beb49c91570014c034c3eaad9ce0a7a37e4c931
> # Parent  37d923cdeba923f4964befcc3d0789362a433a35
> # EXP-Topic debugsetlocks
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 9beb49c91570
> debuglocks: add tests (and fix typo in early return)

Queued, thanks.

> +dolock [wlock] [lock] will set the locks until interrupted
> +  $ dolock() {
> +  >     declare -A options
> +  >     options=([${1:-nolock}]=1 [${2:-nowlock}]=1)

This is Bashism, but I've queued as-is since this line is removed later.

Patch

diff -r 37d923cdeba9 -r 9beb49c91570 mercurial/debugcommands.py
--- a/mercurial/debugcommands.py	Sun Dec 10 22:50:57 2017 -0500
+++ b/mercurial/debugcommands.py	Sun Nov 12 15:34:19 2017 +0100
@@ -1302,7 +1302,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 37d923cdeba9 -r 9beb49c91570 tests/test-debugcommands.t
--- 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