Mercurial > hg
annotate tests/test-filecache.py @ 44003:cb2e2b095dc9
rust-core: updated copyright notice
The intention here is to put an email address that actually
works (I did have full personal copyrights with my
former affiliation).
It is also an opportunity to acknowledge that I've not been
the only one to work on this file.
Differential Revision: https://phab.mercurial-scm.org/D7781
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Wed, 25 Dec 2019 14:53:45 +0100 |
parents | 2372284d9457 |
children | e01ea8325859 |
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 |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
3 import stat |
28741
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
4 import subprocess |
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
5 import sys |
14928 | 6 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
7 if subprocess.call( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
8 ['python', '%s/hghave' % os.environ['TESTDIR'], 'cacheable'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
9 ): |
14928 | 10 sys.exit(80) |
11 | |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
12 print_ = print |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
13 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
14 |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
15 def print(*args, **kwargs): |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
16 """print() wrapper that flushes stdout buffers to avoid py3 buffer issues |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
17 |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
18 We could also just write directly to sys.stdout.buffer the way the |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
19 ui object will, but this was easier for porting the test. |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
20 """ |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
21 print_(*args, **kwargs) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
22 sys.stdout.flush() |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
23 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
24 |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
25 from mercurial import ( |
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
26 extensions, |
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
27 hg, |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
28 localrepo, |
36286
daa5f47558cf
py3: use range instead of xrange on py3 in tests/test-filecache.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31284
diff
changeset
|
29 pycompat, |
28803
76c091f9711e
test-filecache: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents:
28802
diff
changeset
|
30 ui as uimod, |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
31 util, |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
32 vfs as vfsmod, |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
33 ) |
14928 | 34 |
36286
daa5f47558cf
py3: use range instead of xrange on py3 in tests/test-filecache.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31284
diff
changeset
|
35 if pycompat.ispy3: |
daa5f47558cf
py3: use range instead of xrange on py3 in tests/test-filecache.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31284
diff
changeset
|
36 xrange = range |
daa5f47558cf
py3: use range instead of xrange on py3 in tests/test-filecache.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31284
diff
changeset
|
37 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
38 |
14928 | 39 class fakerepo(object): |
40 def __init__(self): | |
41 self._filecache = {} | |
42 | |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
43 class fakevfs(object): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
44 def join(self, p): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
45 return p |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
46 |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
47 vfs = fakevfs() |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
48 |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
49 def unfiltered(self): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
50 return self |
14928 | 51 |
52 def sjoin(self, p): | |
53 return p | |
54 | |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
55 @localrepo.repofilecache('x', 'y') |
14928 | 56 def cached(self): |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
57 print('creating') |
20040
ed80cecdfc57
test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents:
18316
diff
changeset
|
58 return 'string from function' |
14928 | 59 |
60 def invalidate(self): | |
61 for k in self._filecache: | |
62 try: | |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
63 delattr(self, pycompat.sysstr(k)) |
14928 | 64 except AttributeError: |
65 pass | |
66 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
67 |
14928 | 68 def basic(repo): |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
69 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
|
70 # calls function |
14928 | 71 repo.cached |
72 | |
73 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
74 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
|
75 # uses cache |
14928 | 76 repo.cached |
77 | |
78 # create empty file | |
79 f = open('x', 'w') | |
80 f.close() | |
81 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
82 print("* empty file x created") |
14928 | 83 # should recreate the object |
84 repo.cached | |
85 | |
86 f = open('x', 'w') | |
87 f.write('a') | |
88 f.close() | |
89 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
90 print("* file x changed size") |
14928 | 91 # should recreate the object |
92 repo.cached | |
93 | |
94 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
95 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
|
96 # stats file again, reuses object |
14928 | 97 repo.cached |
98 | |
99 # atomic replace file, size doesn't change | |
100 # hopefully st_mtime doesn't change as well so this doesn't use the cache | |
101 # because of inode change | |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
102 f = vfsmod.vfs(b'.')(b'x', b'w', atomictemp=True) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
103 f.write(b'b') |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14982
diff
changeset
|
104 f.close() |
14928 | 105 |
106 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
107 print("* file x changed inode") |
14928 | 108 repo.cached |
109 | |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
110 # create empty file y |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
111 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
112 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
113 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
114 print("* empty file y created") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
115 # should recreate the object |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
116 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
117 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
118 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
119 f.write('A') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
120 f.close() |
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("* file y changed size") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
123 # should recreate the object |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
124 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
125 |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
126 f = vfsmod.vfs(b'.')(b'y', b'w', atomictemp=True) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
127 f.write(b'B') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
128 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
129 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
130 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
131 print("* file y changed inode") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
132 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
133 |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
134 f = vfsmod.vfs(b'.')(b'x', b'w', atomictemp=True) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
135 f.write(b'c') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
136 f.close() |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
137 f = vfsmod.vfs(b'.')(b'y', b'w', atomictemp=True) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
138 f.write(b'C') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
139 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
140 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
141 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
142 print("* both files changed inode") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
143 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
144 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
145 |
14928 | 146 def fakeuncacheable(): |
147 def wrapcacheable(orig, *args, **kwargs): | |
148 return False | |
149 | |
150 def wrapinit(orig, *args, **kwargs): | |
151 pass | |
152 | |
153 originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
154 origcacheable = extensions.wrapfunction( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
155 util.cachestat, 'cacheable', wrapcacheable |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
156 ) |
14928 | 157 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
158 for fn in ['x', 'y']: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
159 try: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
160 os.remove(fn) |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
161 except OSError: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
162 pass |
14928 | 163 |
164 basic(fakerepo()) | |
165 | |
166 util.cachestat.cacheable = origcacheable | |
167 util.cachestat.__init__ = originit | |
168 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
169 |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
170 def test_filecache_synced(): |
26098 | 171 # 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
|
172 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
|
173 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
|
174 # 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
|
175 repo.rollback() |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
176 repo.commit(b'.') |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
177 # 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
|
178 # (file is moved) |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
179 repo.rollback() |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
180 # 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
|
181 # 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
|
182 # it |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
183 repo.commit(b'.') |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
184 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
185 |
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
|
186 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
|
187 os.remove('x') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
188 os.remove('y') |
40424
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37900
diff
changeset
|
189 repo.__class__.cached.set(repo, '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
|
190 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
191 print("* neither file exists") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 f.close() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
197 print("* file x created") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
198 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
|
199 |
40424
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37900
diff
changeset
|
200 repo.__class__.cached.set(repo, 'string 2 set externally') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
201 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
202 print("* string set externally again") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
203 print(repo.cached) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
204 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
205 repo.invalidate() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
206 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
207 f.write('b') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
208 f.close() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
209 print("* file y created") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
210 print(repo.cached) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
211 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
212 |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
213 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
|
214 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
|
215 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
216 # 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
|
217 # "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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
223 oldstat = os.stat(filename) |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
224 if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]: |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
225 # 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
|
226 continue |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
227 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
228 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
|
229 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
230 # repeat changing via checkambigatclosing, to examine whether |
30332
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
29995
diff
changeset
|
231 # 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
|
232 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
|
233 # 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
|
234 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
|
235 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
|
236 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
|
237 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
238 # 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
|
239 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
|
240 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
|
241 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
242 newstat = os.stat(filename) |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
243 if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]: |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
244 # 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
|
245 continue |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
246 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
247 # 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
|
248 # all changes occurred at same time (in sec) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
249 expected = (oldstat[stat.ST_MTIME] + repetition * 2) & 0x7FFFFFFF |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
250 if newstat[stat.ST_MTIME] != expected: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
251 print( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
252 "'newstat[stat.ST_MTIME] %s is not %s (as %s + %s * 2)" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
253 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
254 newstat[stat.ST_MTIME], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
255 expected, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
256 oldstat[stat.ST_MTIME], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
257 repetition, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
258 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
259 ) |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
260 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
261 # 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
|
262 break |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
263 else: |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
264 # 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
|
265 # 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
|
266 # 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
|
267 # 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
|
268 pass |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
269 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40424
diff
changeset
|
270 |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
271 print('basic:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
272 print() |
14928 | 273 basic(fakerepo()) |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
274 print() |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
275 print('fakeuncacheable:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
276 print() |
14928 | 277 fakeuncacheable() |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
278 test_filecache_synced() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
279 print() |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
280 print('setbeforeget:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
281 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
|
282 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
|
283 print() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
284 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
|
285 print() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
286 antiambiguity() |