| 1 |
#require unix-permissions no-root no-windows |
| 2 |
|
| 3 |
Prepare |
| 4 |
|
| 5 |
$ hg init a |
| 6 |
$ echo a > a/a |
| 7 |
$ hg -R a ci -A -m a |
| 8 |
adding a |
| 9 |
|
| 10 |
$ hg clone a b |
| 11 |
updating to branch default |
| 12 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 13 |
|
| 14 |
Test that raising an exception in the release function doesn't cause the lock to choke |
| 15 |
|
| 16 |
$ cat > testlock.py << EOF |
| 17 |
> from mercurial import error, registrar |
| 18 |
> |
| 19 |
> cmdtable = {} |
| 20 |
> command = registrar.command(cmdtable) |
| 21 |
> |
| 22 |
> def acquiretestlock(repo, releaseexc): |
| 23 |
> def unlock(): |
| 24 |
> if releaseexc: |
| 25 |
> raise error.Abort(b'expected release exception') |
| 26 |
> l = repo._lock(repo.vfs, b'testlock', False, unlock, None, b'test lock') |
| 27 |
> return l |
| 28 |
> |
| 29 |
> @command(b'testlockexc') |
| 30 |
> def testlockexc(ui, repo): |
| 31 |
> testlock = acquiretestlock(repo, True) |
| 32 |
> try: |
| 33 |
> testlock.release() |
| 34 |
> finally: |
| 35 |
> try: |
| 36 |
> testlock = acquiretestlock(repo, False) |
| 37 |
> except error.LockHeld: |
| 38 |
> raise error.Abort(b'lockfile on disk even after releasing!') |
| 39 |
> testlock.release() |
| 40 |
> EOF |
| 41 |
$ cat >> $HGRCPATH << EOF |
| 42 |
> [extensions] |
| 43 |
> testlock=$TESTTMP/testlock.py |
| 44 |
> EOF |
| 45 |
|
| 46 |
$ hg -R b testlockexc |
| 47 |
abort: expected release exception |
| 48 |
[255] |
| 49 |
|
| 50 |
One process waiting for another |
| 51 |
|
| 52 |
$ SYNC_FILE_LOCKED="$TESTTMP/sync-file-locked" |
| 53 |
$ export SYNC_FILE_LOCKED |
| 54 |
$ SYNC_FILE_TRYING_LOCK="$TESTTMP/sync-file-trying-lock" |
| 55 |
$ export SYNC_FILE_TRYING_LOCK |
| 56 |
$ cat << EOF > locker.sh |
| 57 |
> $RUNTESTDIR/testlib/wait-on-file 10 $SYNC_FILE_TRYING_LOCK $SYNC_FILE_LOCKED; |
| 58 |
> EOF |
| 59 |
$ cat << EOF > waiter.sh |
| 60 |
> $RUNTESTDIR/testlib/wait-on-file 10 $SYNC_FILE_LOCKED; |
| 61 |
> EOF |
| 62 |
$ clean_sync() { |
| 63 |
> rm -f "$SYNC_FILE_LOCKED" |
| 64 |
> rm -f "$SYNC_FILE_TRYING_LOCK" |
| 65 |
> } |
| 66 |
|
| 67 |
|
| 68 |
$ clean_sync |
| 69 |
$ echo b > b/b |
| 70 |
$ hg -R b ci -A -m b \ |
| 71 |
> --config hooks.precommit="sh $TESTTMP/locker.sh" \ |
| 72 |
> > stdout & |
| 73 |
$ hg -R b up -q \ |
| 74 |
> --config ui.timeout.warn=0 \ |
| 75 |
> --config hooks.pre-update="sh $TESTTMP/waiter.sh" \ |
| 76 |
> --config devel.lock-wait-sync-file="$SYNC_FILE_TRYING_LOCK" \ |
| 77 |
> > preup-stdout 2> preup-stderr |
| 78 |
$ wait |
| 79 |
$ cat preup-stdout |
| 80 |
$ cat preup-stderr |
| 81 |
waiting for lock on working directory of b held by process '*' on host '*' (glob) |
| 82 |
got lock after * seconds (glob) |
| 83 |
$ cat stdout |
| 84 |
adding b |
| 85 |
|
| 86 |
On processs waiting on another, warning after a long time. |
| 87 |
|
| 88 |
$ clean_sync |
| 89 |
$ echo b > b/c |
| 90 |
$ hg -R b ci -A -m b \ |
| 91 |
> --config hooks.precommit="sh $TESTTMP/locker.sh" \ |
| 92 |
> > stdout & |
| 93 |
$ hg -R b up -q \ |
| 94 |
> --config hooks.pre-update="sh $TESTTMP/waiter.sh" \ |
| 95 |
> --config devel.lock-wait-sync-file="$SYNC_FILE_TRYING_LOCK" \ |
| 96 |
> --config ui.timeout.warn=250 \ |
| 97 |
> > preup-stdout 2> preup-stderr |
| 98 |
$ wait |
| 99 |
$ cat preup-stdout |
| 100 |
$ cat preup-stderr |
| 101 |
$ cat stdout |
| 102 |
adding c |
| 103 |
|
| 104 |
On processs waiting on another, warning disabled. |
| 105 |
|
| 106 |
$ clean_sync |
| 107 |
$ echo b > b/d |
| 108 |
$ hg -R b ci -A -m b \ |
| 109 |
> --config hooks.precommit="sh $TESTTMP/locker.sh" \ |
| 110 |
> > stdout & |
| 111 |
$ hg -R b up -q \ |
| 112 |
> --config hooks.pre-update="sh $TESTTMP/waiter.sh" \ |
| 113 |
> --config devel.lock-wait-sync-file="$SYNC_FILE_TRYING_LOCK" \ |
| 114 |
> --config ui.timeout.warn=-1 \ |
| 115 |
> > preup-stdout 2>preup-stderr |
| 116 |
$ wait |
| 117 |
$ cat preup-stdout |
| 118 |
$ cat preup-stderr |
| 119 |
$ cat stdout |
| 120 |
adding d |
| 121 |
|
| 122 |
check we still print debug output |
| 123 |
|
| 124 |
On processs waiting on another, warning after a long time (debug output on) |
| 125 |
|
| 126 |
$ clean_sync |
| 127 |
$ echo b > b/e |
| 128 |
$ hg -R b ci -A -m b \ |
| 129 |
> --config hooks.precommit="sh $TESTTMP/locker.sh" \ |
| 130 |
> > stdout & |
| 131 |
$ hg -R b up \ |
| 132 |
> --config hooks.pre-update="sh $TESTTMP/waiter.sh" \ |
| 133 |
> --config devel.lock-wait-sync-file="$SYNC_FILE_TRYING_LOCK" \ |
| 134 |
> --config ui.timeout.warn=250 --debug \ |
| 135 |
> > preup-stdout 2>preup-stderr |
| 136 |
$ wait |
| 137 |
$ cat preup-stdout |
| 138 |
running hook pre-update: sh $TESTTMP/waiter.sh |
| 139 |
waiting for lock on working directory of b held by process '*' on host '*' (glob) |
| 140 |
got lock after * seconds (glob) |
| 141 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 142 |
$ cat preup-stderr |
| 143 |
$ cat stdout |
| 144 |
adding e |
| 145 |
|
| 146 |
On processs waiting on another, warning disabled, (debug output on) |
| 147 |
|
| 148 |
$ clean_sync |
| 149 |
$ echo b > b/f |
| 150 |
$ hg -R b ci -A -m b \ |
| 151 |
> --config hooks.precommit="sh $TESTTMP/locker.sh" \ |
| 152 |
> > stdout & |
| 153 |
$ hg -R b up \ |
| 154 |
> --config hooks.pre-update="sh $TESTTMP/waiter.sh" \ |
| 155 |
> --config devel.lock-wait-sync-file="$SYNC_FILE_TRYING_LOCK" \ |
| 156 |
> --config ui.timeout.warn=-1 --debug\ |
| 157 |
> > preup-stdout 2>preup-stderr |
| 158 |
$ wait |
| 159 |
$ cat preup-stdout |
| 160 |
running hook pre-update: sh $TESTTMP/waiter.sh |
| 161 |
waiting for lock on working directory of b held by process '*' on host '*' (glob) |
| 162 |
got lock after * seconds (glob) |
| 163 |
0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 164 |
$ cat preup-stderr |
| 165 |
$ cat stdout |
| 166 |
adding f |
| 167 |
|
| 168 |
Pushing to a local read-only repo that can't be locked |
| 169 |
|
| 170 |
$ chmod 100 a/.hg/store |
| 171 |
|
| 172 |
$ hg -R b push a |
| 173 |
pushing to a |
| 174 |
searching for changes |
| 175 |
abort: could not lock repository a: $EACCES$ |
| 176 |
[20] |
| 177 |
|
| 178 |
$ chmod 700 a/.hg/store |