Mercurial > hg-stable
changeset 35401:a43b2dd95e4f
debuglocks: add tests (and fix typo in early return)
author | Paul Morelle <paul.morelle@octobus.net> |
---|---|
date | Sun, 12 Nov 2017 15:34:19 +0100 |
parents | 4441705b7111 |
children | 12055fb3ba30 |
files | mercurial/debugcommands.py tests/test-debugcommands.t |
diffstat | 2 files changed, 117 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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()
--- 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