tests/test-symlink-os-yes-fs-no.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 02 Dec 2015 03:12:07 +0900
changeset 27192 a01d3d32b53a
parent 18178 6ae45c0b4625
child 28916 3b453513f1fe
permissions -rw-r--r--
commands: make commit acquire locks before processing (issue4368) Before this patch, "hg commit" (process A) executes steps below: 1. get current branch heads via 'repo.branchheads()' - cache 'repo.changelog' 2. invoke 'repo.commit()' 3. acquire wlock - invalidate 'repo.dirstate' 4. access 'repo.dirstate' - re-read '.hg/dirstate' - check validity of parent revisions with 'repo.changelog' 5. invoke 'repo.commitctx()' 6. acquire store lock (slock) - invalidate 'repo.changelog' 7. do committing 8. release slock 9. release wlock 10. check new branch head (via 'cmdutil.commitstatus()') If acquisition of wlock at (3) above waits for another "hg commit" (process B) or so running parallelly to release wlock, process A causes creating orphan revision, because: - '.hg/dirstate' refers the revision, which is newly added by process B, as its parent - but already cached 'repo.changelog' doesn't contain such revision - therefore, validating parents of '.hg/dirstate' at (4) above replaces such revision with 'nullid' Then, process A creates "orphan" revision, of which parent is "null" revision. In addition to it, "created new head" may be shown at the end of process A unintentionally, if store is updated parallelly, because both getting branch heads (1) and checking new branch head (10) are executed outside slock scope. To avoid this issue, this patch makes "hg commit" acquire wlock and slock before processing. This patch resolves the issue between "hg commit" processes, but not one between "hg commit" and other commands. Subsequent patches resolve the latter. Even after this patch, there are still corner case problems below: - filecache may overlook changes of '.hg/dirstate', and it causes similar issue (see below for detail) https://bz.mercurial-scm.org/show_bug.cgi?id=4368#c10 - 3rd party extension may cause similar issue, if it directly uses 'repo.commit()' without acquisition of wlock and slock This can be fixed by acquisition of slock at the beginning of 'repo.commit()', but it seems suitable for "default" branch In fact, acquisition of slock itself is already introduced at "default" branch by 4414d500604f, but acquisition is not at the beginning of 'repo.commit()'. This patch also changes some tests: - test-fncache.t needs this tricky wrapping, to release (= forced failure of) wlock certainly - order of "hg commit" output is changed by widening scope of locks, because some hooks are fired after releasing wlock
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
     1
import os, sys, time
14168
135e244776f0 prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 14116
diff changeset
     2
from mercurial import hg, ui, commands, util
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
     3
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
     4
TESTDIR = os.environ["TESTDIR"]
14116
cd3032437064 tests: move test bundles in a bundles/ subdirectory
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11769
diff changeset
     5
BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg')
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
     6
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
     7
# only makes sense to test on os which supports symlinks
14971
0b21ae0a2366 tests: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14553
diff changeset
     8
if not getattr(os, "symlink", False):
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
     9
    sys.exit(80) # SKIPPED_STATUS defined in run-tests.py
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    10
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    11
u = ui.ui()
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    12
# hide outer repo
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    13
hg.peer(u, {}, '.', create=True)
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    14
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    15
# clone with symlink support
14553
d976542986d2 hg: add opts argument to clone for internal remoteui
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14168
diff changeset
    16
hg.clone(u, {}, BUNDLEPATH, 'test0')
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    17
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    18
repo = hg.repository(u, 'test0')
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    19
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    20
# wait a bit, or the status call wont update the dirstate
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    21
time.sleep(1)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    22
commands.status(u, repo)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    23
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    24
# now disable symlink support -- this is what os.symlink would do on a
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    25
# non-symlink file system
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    26
def symlink_failure(src, dst):
18178
6ae45c0b4625 test-symlink-os-yes-fs-no.py: clean up use of two-argument raise
Augie Fackler <raf@durin42.com>
parents: 17015
diff changeset
    27
    raise OSError(1, "Operation not permitted")
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    28
os.symlink = symlink_failure
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    29
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    30
# dereference links as if a Samba server has exported this to a
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    31
# Windows client
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    32
for f in 'test0/a.lnk', 'test0/d/b.lnk':
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    33
    os.unlink(f)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    34
    fp = open(f, 'wb')
14168
135e244776f0 prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 14116
diff changeset
    35
    fp.write(util.readfile(f[:-4]))
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    36
    fp.close()
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    37
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    38
# reload repository
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    39
u = ui.ui()
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    40
repo = hg.repository(u, 'test0')
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    41
commands.status(u, repo)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    42
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    43
# try cloning a repo which contains symlinks
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    44
u = ui.ui()
14553
d976542986d2 hg: add opts argument to clone for internal remoteui
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14168
diff changeset
    45
hg.clone(u, {}, BUNDLEPATH, 'test1')