tests/test-symlink-os-yes-fs-no.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sat, 27 Feb 2016 18:22:49 -0800
branchstable
changeset 28289 d493d64757eb
parent 18178 6ae45c0b4625
child 28916 3b453513f1fe
permissions -rw-r--r--
hg: obtain lock when creating share from pooled repo (issue5104) There are race conditions between clients performing a shared clone to pooled storage: 1) Clients race to create the new shared repo in the pool directory 2) 1 client is seeding the repo in the pool directory and another goes to share it before it is fully cloned We prevent these race conditions by obtaining a lock in the pool directory that is derived from the name of the repo we will be accessing. To test this, a simple generic "lockdelay" extension has been added. The extension inserts an optional, configurable delay before or after lock acquisition. In the test, we delay 2 seconds after lock acquisition in the first process and 1 second before lock acquisition in the 2nd process. This means the first process has 1s to obtain the lock. There is a race condition here. If we encounter it in the wild, we could change the dummy extension to wait on the lock file to appear instead of relying on timing. But that's more complicated. Let's see what happens first.
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')