tests/test-debugcommands.t
changeset 35402 12055fb3ba30
parent 35401 a43b2dd95e4f
child 35678 43154a76f392
equal deleted inserted replaced
35401:a43b2dd95e4f 35402:12055fb3ba30
     1   $ cat << EOF >> $HGRCPATH
     1   $ cat << EOF >> $HGRCPATH
       
     2   > [ui]
       
     3   > interactive=yes
     2   > [format]
     4   > [format]
     3   > usegeneraldelta=yes
     5   > usegeneraldelta=yes
     4   > EOF
     6   > EOF
     5 
     7 
     6   $ hg init debugrevlog
     8   $ hg init debugrevlog
   155 
   157 
   156 waitlock <file> will wait for file to be created. If it isn't in a reasonable
   158 waitlock <file> will wait for file to be created. If it isn't in a reasonable
   157 amount of time, displays error message and returns 1
   159 amount of time, displays error message and returns 1
   158   $ waitlock() {
   160   $ waitlock() {
   159   >     start=`date +%s`
   161   >     start=`date +%s`
   160   >     timeout=1
   162   >     timeout=5
   161   >     while [ \( ! -f $1 \) -a \( ! -L $1 \) ]; do
   163   >     while [ \( ! -f $1 \) -a \( ! -L $1 \) ]; do
   162   >         now=`date +%s`
   164   >         now=`date +%s`
   163   >         if [ "`expr $now - $start`" -gt $timeout ]; then
   165   >         if [ "`expr $now - $start`" -gt $timeout ]; then
   164   >             echo "timeout: $1 was not created in $timeout seconds"
   166   >             echo "timeout: $1 was not created in $timeout seconds"
   165   >             return 1
   167   >             return 1
   166   >         fi
   168   >         fi
   167   >         sleep 0.1
   169   >         sleep 0.1
   168   >     done
   170   >     done
   169   > }
   171   > }
   170 dolock [wlock] [lock] will set the locks until interrupted
       
   171   $ dolock() {
   172   $ dolock() {
   172   >     declare -A options
   173   >     {
   173   >     options=([${1:-nolock}]=1 [${2:-nowlock}]=1)
   174   >         waitlock .hg/unlock
   174   >     python <<EOF
   175   >         rm -f .hg/unlock
   175   > from mercurial import hg, ui as uimod
   176   >         echo y
   176   > import os
   177   >     } | hg debuglocks "$@" > /dev/null
   177   > import time
       
   178   > 
       
   179   > repo = hg.repository(uimod.ui.load(), path='.')
       
   180   > `[ -n "${options["wlock"]}" ] && echo "with repo.wlock(False):" || echo "if True:"`
       
   181   >     `[ -n "${options["lock"]}" ] && echo "with repo.lock(False):" || echo "if True:"`
       
   182   >         while not os.path.exists('.hg/unlock'):
       
   183   >             time.sleep(0.1)
       
   184   > os.unlink('.hg/unlock')
       
   185   > EOF
       
   186   > }
   178   > }
   187 
   179   $ dolock -s &
   188   $ dolock lock &
       
   189   $ waitlock .hg/store/lock
   180   $ waitlock .hg/store/lock
   190 
   181 
   191   $ hg debuglocks
   182   $ hg debuglocks
   192   lock:  user *, process * (*s) (glob)
   183   lock:  user *, process * (*s) (glob)
   193   wlock: free
   184   wlock: free
   194   [1]
   185   [1]
   195   $ touch .hg/unlock
   186   $ touch .hg/unlock
   196   $ wait
   187   $ wait
       
   188   $ [ -f .hg/store/lock ] || echo "There is no lock"
       
   189   There is no lock
   197 
   190 
   198 * Test setting the wlock
   191 * Test setting the wlock
   199 
   192 
   200   $ dolock wlock &
   193   $ dolock -S &
   201   $ waitlock .hg/wlock
   194   $ waitlock .hg/wlock
   202 
   195 
   203   $ hg debuglocks
   196   $ hg debuglocks
   204   lock:  free
   197   lock:  free
   205   wlock: user *, process * (*s) (glob)
   198   wlock: user *, process * (*s) (glob)
   206   [1]
   199   [1]
   207   $ touch .hg/unlock
   200   $ touch .hg/unlock
   208   $ wait
   201   $ wait
       
   202   $ [ -f .hg/wlock ] || echo "There is no wlock"
       
   203   There is no wlock
   209 
   204 
   210 * Test setting both locks
   205 * Test setting both locks
   211 
   206 
   212   $ dolock wlock lock &
   207   $ dolock -Ss &
   213   $ waitlock .hg/wlock && waitlock .hg/store/lock
   208   $ waitlock .hg/wlock && waitlock .hg/store/lock
   214 
   209 
   215   $ hg debuglocks
   210   $ hg debuglocks
   216   lock:  user *, process * (*s) (glob)
   211   lock:  user *, process * (*s) (glob)
   217   wlock: user *, process * (*s) (glob)
   212   wlock: user *, process * (*s) (glob)
   218   [2]
   213   [2]
       
   214 
       
   215 * Test failing to set a lock
       
   216 
       
   217   $ hg debuglocks -s
       
   218   abort: lock is already held
       
   219   [255]
       
   220 
       
   221   $ hg debuglocks -S
       
   222   abort: wlock is already held
       
   223   [255]
       
   224 
   219   $ touch .hg/unlock
   225   $ touch .hg/unlock
   220   $ wait
   226   $ wait
   221 
   227 
   222   $ hg debuglocks
   228   $ hg debuglocks
   223   lock:  free
   229   lock:  free
   224   wlock: free
   230   wlock: free
   225 
   231 
   226 * Test forcing the lock
   232 * Test forcing the lock
   227 
   233 
   228   $ dolock lock &
   234   $ dolock -s &
   229   $ waitlock .hg/store/lock
   235   $ waitlock .hg/store/lock
   230 
   236 
   231   $ hg debuglocks
   237   $ hg debuglocks
   232   lock:  user *, process * (*s) (glob)
   238   lock:  user *, process * (*s) (glob)
   233   wlock: free
   239   wlock: free
   242   $ touch .hg/unlock
   248   $ touch .hg/unlock
   243   $ wait
   249   $ wait
   244 
   250 
   245 * Test forcing the wlock
   251 * Test forcing the wlock
   246 
   252 
   247   $ dolock wlock &
   253   $ dolock -S &
   248   $ waitlock .hg/wlock
   254   $ waitlock .hg/wlock
   249 
   255 
   250   $ hg debuglocks
   256   $ hg debuglocks
   251   lock:  free
   257   lock:  free
   252   wlock: user *, process * (*s) (glob)
   258   wlock: user *, process * (*s) (glob)