Mercurial > hg
annotate tests/test-filecache.py @ 36043:223ed0b53f08
py3: more robustly cast UUID to bytes
The UUID type only has __str__ implemented. So we need to cast to
bytes on Python 3.
We need an actual bytes instance here (bytestr won't do) because
the re.escape() later iterates over characters and characters
need to behave like ints, not bytes instances of length 1.
Differential Revision: https://phab.mercurial-scm.org/D2144
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 11 Feb 2018 13:23:26 -0800 |
parents | 74cbbd5420ba |
children | daa5f47558cf |
rev | line source |
---|---|
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
1 from __future__ import absolute_import, print_function |
28741
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
2 import os |
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
3 import subprocess |
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
4 import sys |
14928 | 5 |
16683 | 6 if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], |
7 'cacheable']): | |
14928 | 8 sys.exit(80) |
9 | |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
10 from mercurial import ( |
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
11 extensions, |
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
12 hg, |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
13 localrepo, |
28803
76c091f9711e
test-filecache: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents:
28802
diff
changeset
|
14 ui as uimod, |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
15 util, |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
16 vfs as vfsmod, |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
17 ) |
14928 | 18 |
19 class fakerepo(object): | |
20 def __init__(self): | |
21 self._filecache = {} | |
22 | |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
23 class fakevfs(object): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
24 |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
25 def join(self, p): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
26 return p |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
27 |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
28 vfs = fakevfs() |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
29 |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
30 def unfiltered(self): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
31 return self |
14928 | 32 |
33 def sjoin(self, p): | |
34 return p | |
35 | |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
36 @localrepo.repofilecache('x', 'y') |
14928 | 37 def cached(self): |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
38 print('creating') |
20040
ed80cecdfc57
test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents:
18316
diff
changeset
|
39 return 'string from function' |
14928 | 40 |
41 def invalidate(self): | |
42 for k in self._filecache: | |
43 try: | |
44 delattr(self, k) | |
45 except AttributeError: | |
46 pass | |
47 | |
48 def basic(repo): | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
49 print("* neither file exists") |
20041
42deff43460a
test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents:
20040
diff
changeset
|
50 # calls function |
14928 | 51 repo.cached |
52 | |
53 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
54 print("* neither file still exists") |
20041
42deff43460a
test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents:
20040
diff
changeset
|
55 # uses cache |
14928 | 56 repo.cached |
57 | |
58 # create empty file | |
59 f = open('x', 'w') | |
60 f.close() | |
61 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
62 print("* empty file x created") |
14928 | 63 # should recreate the object |
64 repo.cached | |
65 | |
66 f = open('x', 'w') | |
67 f.write('a') | |
68 f.close() | |
69 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
70 print("* file x changed size") |
14928 | 71 # should recreate the object |
72 repo.cached | |
73 | |
74 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
75 print("* nothing changed with either file") |
20041
42deff43460a
test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents:
20040
diff
changeset
|
76 # stats file again, reuses object |
14928 | 77 repo.cached |
78 | |
79 # atomic replace file, size doesn't change | |
80 # hopefully st_mtime doesn't change as well so this doesn't use the cache | |
81 # because of inode change | |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
82 f = vfsmod.vfs('.')('x', 'w', atomictemp=True) |
14928 | 83 f.write('b') |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14982
diff
changeset
|
84 f.close() |
14928 | 85 |
86 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
87 print("* file x changed inode") |
14928 | 88 repo.cached |
89 | |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
90 # create empty file y |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
91 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
92 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
93 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
94 print("* empty file y created") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
95 # should recreate the object |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
96 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
97 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
98 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
99 f.write('A') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
100 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
101 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
102 print("* file y changed size") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
103 # should recreate the object |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
104 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
105 |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
106 f = vfsmod.vfs('.')('y', 'w', atomictemp=True) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
107 f.write('B') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
108 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
109 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
110 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
111 print("* file y changed inode") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
112 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
113 |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
114 f = vfsmod.vfs('.')('x', 'w', atomictemp=True) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
115 f.write('c') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
116 f.close() |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
117 f = vfsmod.vfs('.')('y', 'w', atomictemp=True) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
118 f.write('C') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
119 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
120 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
121 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
122 print("* both files changed inode") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
123 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
124 |
14928 | 125 def fakeuncacheable(): |
126 def wrapcacheable(orig, *args, **kwargs): | |
127 return False | |
128 | |
129 def wrapinit(orig, *args, **kwargs): | |
130 pass | |
131 | |
132 originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) | |
14937
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
133 origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', |
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
134 wrapcacheable) |
14928 | 135 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
136 for fn in ['x', 'y']: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
137 try: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
138 os.remove(fn) |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
139 except OSError: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
140 pass |
14928 | 141 |
142 basic(fakerepo()) | |
143 | |
144 util.cachestat.cacheable = origcacheable | |
145 util.cachestat.__init__ = originit | |
146 | |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
147 def test_filecache_synced(): |
26098 | 148 # test old behavior that caused filecached properties to go out of sync |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
149 os.system('hg init && echo a >> a && hg ci -qAm.') |
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30332
diff
changeset
|
150 repo = hg.repository(uimod.ui.load()) |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
151 # first rollback clears the filecache, but changelog to stays in __dict__ |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
152 repo.rollback() |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
153 repo.commit('.') |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
154 # second rollback comes along and touches the changelog externally |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
155 # (file is moved) |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
156 repo.rollback() |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
157 # but since changelog isn't under the filecache control anymore, we don't |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
158 # see that it changed, and return the old changelog without reconstructing |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
159 # it |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
160 repo.commit('.') |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
161 |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
162 def setbeforeget(repo): |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
163 os.remove('x') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
164 os.remove('y') |
20040
ed80cecdfc57
test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents:
18316
diff
changeset
|
165 repo.cached = 'string set externally' |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
166 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
167 print("* neither file exists") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
168 print(repo.cached) |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
169 repo.invalidate() |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
170 f = open('x', 'w') |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
171 f.write('a') |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
172 f.close() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
173 print("* file x created") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
174 print(repo.cached) |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
175 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
176 repo.cached = 'string 2 set externally' |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
177 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
178 print("* string set externally again") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
179 print(repo.cached) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
180 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
181 repo.invalidate() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
182 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
183 f.write('b') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
184 f.close() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
185 print("* file y created") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
186 print(repo.cached) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
187 |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
188 def antiambiguity(): |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
189 filename = 'ambigcheck' |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
190 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
191 # try some times, because reproduction of ambiguity depends on |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
192 # "filesystem time" |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
193 for i in xrange(5): |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
194 fp = open(filename, 'w') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
195 fp.write('FOO') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
196 fp.close() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
197 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
198 oldstat = os.stat(filename) |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
199 if oldstat.st_ctime != oldstat.st_mtime: |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
200 # subsequent changing never causes ambiguity |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
201 continue |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
202 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
203 repetition = 3 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
204 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
205 # repeat changing via checkambigatclosing, to examine whether |
30332
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
29995
diff
changeset
|
206 # st_mtime is advanced multiple times as expected |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
207 for i in xrange(repetition): |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
208 # explicit closing |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
209 fp = vfsmod.checkambigatclosing(open(filename, 'a')) |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
210 fp.write('FOO') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
211 fp.close() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
212 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
213 # implicit closing by "with" statement |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
214 with vfsmod.checkambigatclosing(open(filename, 'a')) as fp: |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
215 fp.write('BAR') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
216 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
217 newstat = os.stat(filename) |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
218 if oldstat.st_ctime != newstat.st_ctime: |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
219 # timestamp ambiguity was naturally avoided while repetition |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
220 continue |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
221 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
222 # st_mtime should be advanced "repetition * 2" times, because |
30332
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
29995
diff
changeset
|
223 # all changes occurred at same time (in sec) |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
224 expected = (oldstat.st_mtime + repetition * 2) & 0x7fffffff |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
225 if newstat.st_mtime != expected: |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
226 print("'newstat.st_mtime %s is not %s (as %s + %s * 2)" % |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
227 (newstat.st_mtime, expected, oldstat.st_mtime, repetition)) |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
228 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
229 # no more examination is needed regardless of result |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
230 break |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
231 else: |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
232 # This platform seems too slow to examine anti-ambiguity |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
233 # of file timestamp (or test happened to be executed at |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
234 # bad timing). Exit silently in this case, because running |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
235 # on other faster platforms can detect problems |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
236 pass |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
237 |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
238 print('basic:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
239 print() |
14928 | 240 basic(fakerepo()) |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
241 print() |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
242 print('fakeuncacheable:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
243 print() |
14928 | 244 fakeuncacheable() |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
245 test_filecache_synced() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
246 print() |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
247 print('setbeforeget:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
248 print() |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
249 setbeforeget(fakerepo()) |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
250 print() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
251 print('antiambiguity:') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
252 print() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
253 antiambiguity() |