Mercurial > hg
annotate tests/test-lock-badness.t @ 26750:9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
Before this patch, external editor process for the commit log can't
view some in-memory changes (especially, of dirstate), because they
aren't written out until the end of transaction (or wlock).
This causes unexpected output of Mercurial commands spawned from that
editor process.
To make in-memory changes visible to external editor process, this
patch does:
- write (or schedule to write) in-memory dirstate changes, and
- set HG_PENDING environment variable, if:
- a transaction is running, and
- there are in-memory changes to be visible
"hg diff" spawned from external editor process for "hg qrefresh"
shows:
- "changes newly imported into the topmost" before 49148d7868df(*)
- "all changes recorded in the topmost by refreshing" after this patch
(*) 49148d7868df changed steps invoking editor process
Even though backward compatibility may be broken, the latter behavior
looks reasonable, because "hg diff" spawned from the editor process
consistently shows "what changes new revision records" regardless of
invocation context.
In fact, issue4378 itself should be resolved by 800e090e9c64, which
made 'repo.transaction()' write in-memory dirstate changes out
explicitly before starting transaction. It also made "hg qrefresh"
imply 'dirstate.write()' before external editor invocation in call
chain below.
- mq.queue.refresh
- strip.strip
- repair.strip
- localrepository.transaction
- dirstate.write
- localrepository.commit
- invoke external editor
Though, this patch has '(issue4378)' in own summary line to indicate
that issues like issue4378 should be fixed by this.
BTW, this patch adds '-m' option to a 'hg ci --amend' execution in
'test-commit-amend.t', to avoid invoking external editor process.
In this case, "unsure" states may be changed to "clean" according to
timestamp or so on. These changes should be written into pending file,
if external editor invocation is required,
Then, writing dirstate changes out breaks stability of test, because
it shows "transaction abort!/rollback completed" occasionally.
Aborting after editor process invocation while commands below may
cause similar instability of tests, too (AFAIK, there is no more such
one, at this revision)
- commit --amend
- without --message/--logfile
- import
- without --message/--logfile,
- without --no-commit,
- without --bypass,
- one of below, and
- patch has no description text, or
- with --edit
- aborting at the 1st patch, which adds or removes file(s)
- if it only changes existing files, status is checked only for
changed files by 'scmutil.matchfiles()', and transition from
"unsure" to "normal" in dirstate doesn't occur (= dirstate
isn't changed, and written out)
- aborting at the 2nd or later patch implies other pending
changes (e.g. changelog), and always causes showing
"transaction abort!/rollback completed"
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sat, 17 Oct 2015 01:15:34 +0900 |
parents | 56b2bcea2529 |
children | 38292b227deb |
rev | line source |
---|---|
22047
8fb6844a4ff1
tests: change some #ifs to #requires
Matt Mackall <mpm@selenic.com>
parents:
20969
diff
changeset
|
1 #require unix-permissions no-root no-windows |
20380
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
2 |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
3 Prepare |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
4 |
12071
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
5 $ hg init a |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
6 $ echo a > a/a |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
7 $ hg -R a ci -A -m a |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
8 adding a |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
9 |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
10 $ hg clone a b |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
11 updating to branch default |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
12 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
2016
ff5c9a92f556
fix backtrace printed when cannot get lock.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
13 |
23032
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
14 Test that raising an exception in the release function doesn't cause the lock to choke |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
15 |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
16 $ cat > testlock.py << EOF |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26028
diff
changeset
|
17 > from mercurial import cmdutil, error, error |
23032
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
18 > |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
19 > cmdtable = {} |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
20 > command = cmdutil.command(cmdtable) |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
21 > |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
22 > def acquiretestlock(repo, releaseexc): |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
23 > def unlock(): |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
24 > if releaseexc: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26028
diff
changeset
|
25 > raise error.Abort('expected release exception') |
23032
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
26 > l = repo._lock(repo.vfs, 'testlock', False, unlock, None, 'test lock') |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
27 > return l |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
28 > |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
29 > @command('testlockexc') |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
30 > def testlockexc(ui, repo): |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
31 > testlock = acquiretestlock(repo, True) |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
32 > try: |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
33 > testlock.release() |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
34 > finally: |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
35 > try: |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
36 > testlock = acquiretestlock(repo, False) |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
37 > except error.LockHeld: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26028
diff
changeset
|
38 > raise error.Abort('lockfile on disk even after releasing!') |
23032
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
39 > testlock.release() |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
40 > EOF |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
41 $ cat >> $HGRCPATH << EOF |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
42 > [extensions] |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
43 > testlock=$TESTTMP/testlock.py |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
44 > EOF |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
45 |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
46 $ hg -R b testlockexc |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
47 abort: expected release exception |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
48 [255] |
f484be02bd35
lock: while releasing, unlink lockfile even if the release function throws
Siddharth Agarwal <sid0@fb.com>
parents:
22047
diff
changeset
|
49 |
20380
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
50 One process waiting for another |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
51 |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
52 $ cat > hooks.py << EOF |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
53 > import time |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
54 > def sleepone(**x): time.sleep(1) |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
55 > def sleephalf(**x): time.sleep(0.5) |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
56 > EOF |
12071
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
57 $ echo b > b/b |
20380
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
58 $ hg -R b ci -A -m b --config hooks.precommit="python:`pwd`/hooks.py:sleepone" > stdout & |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
59 $ hg -R b up -q --config hooks.pre-update="python:`pwd`/hooks.py:sleephalf" |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
60 waiting for lock on working directory of b held by '*:*' (glob) |
20653
3bfac190c7cd
tests: match time by a glob to fix intermittent failures of test-lock-badness.t
Simon Heimberg <simohe@besonet.ch>
parents:
20380
diff
changeset
|
61 got lock after ? seconds (glob) |
20380
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
62 $ wait |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
63 $ cat stdout |
12071
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
64 adding b |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
65 |
20380
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
66 Pushing to a local read-only repo that can't be locked |
c697b70f295f
localrepo: give a sigh of relief when getting lock after waiting for it
Mads Kiilerich <madski@unity3d.com>
parents:
20008
diff
changeset
|
67 |
12071
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
68 $ chmod 100 a/.hg/store |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
69 |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
70 $ hg -R b push a |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
71 pushing to a |
20969
7a679918ee2b
localrepo: add unbundle support
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20653
diff
changeset
|
72 searching for changes |
12071
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
73 abort: could not lock repository a: Permission denied |
12316
4134686b83e1
tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents:
12071
diff
changeset
|
74 [255] |
12071
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
75 |
45ff6dcf82ea
tests: unify test-lock-badness
Adrian Buehlmann <adrian@cadifra.com>
parents:
3853
diff
changeset
|
76 $ chmod 700 a/.hg/store |