Mercurial > hg
annotate tests/test-hgwebdir-paths.py @ 34107:4f60720cf0df
blackbox: fix rotation with chg
The added test will show:
$ $PYTHON showsize.py .hg/blackbox*
.hg/blackbox.log: < 500
.hg/blackbox.log.1: < 500
.hg/blackbox.log.2: < 500
.hg/blackbox.log.3: < 500
.hg/blackbox.log.4: < 500
.hg/blackbox.log.5: >= 500
with previous code.
The issue is caused by blackbox caching file objects *by path*, and the
rotation size check could run on a wrong file object (i.e. it should check
"blackbox.log", but `filehandles["blackbox.log"]` contains a file object
that has been renamed to "blackbox.log.5").
This patch removes the "filehandlers" global cache added by 45313f5a3a8c to
solve the issue.
I think the original patch was trying to make different ui objects use a same
file object if their blackbox.log path is the same. In theory it could also
be problematic in the rotation case. Anyway, that should become unnecessary
after D650.
Differential Revision: https://phab.mercurial-scm.org/D648
author | Jun Wu <quark@fb.com> |
---|---|
date | Wed, 06 Sep 2017 19:27:30 -0700 |
parents | d83ca854fa21 |
children | 81455f482478 |
rev | line source |
---|---|
28932
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
1 from __future__ import absolute_import |
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
2 |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
3 import os |
28932
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
4 from mercurial import ( |
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
5 hg, |
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
6 ui as uimod, |
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
7 ) |
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
8 from mercurial.hgweb import ( |
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
9 hgwebdir_mod, |
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
10 ) |
4eac86331acb
tests: make test-hgwebdir-paths use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
15381
diff
changeset
|
11 hgwebdir = hgwebdir_mod.hgwebdir |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
12 |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
13 os.mkdir('webdir') |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
14 os.chdir('webdir') |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
15 |
15381
c519cd8f0169
backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents:
15355
diff
changeset
|
16 webdir = os.path.realpath('.') |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
17 |
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
28932
diff
changeset
|
18 u = uimod.ui.load() |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
19 hg.repository(u, 'a', create=1) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
20 hg.repository(u, 'b', create=1) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
21 os.chdir('b') |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
22 hg.repository(u, 'd', create=1) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
23 os.chdir('..') |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
24 hg.repository(u, 'c', create=1) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
25 os.chdir('..') |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
26 |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
27 paths = {'t/a/': '%s/a' % webdir, |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
28 'b': '%s/b' % webdir, |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
29 'coll': '%s/*' % webdir, |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
30 'rcoll': '%s/**' % webdir} |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
31 |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
32 config = os.path.join(webdir, 'hgwebdir.conf') |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
33 configfile = open(config, 'w') |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
34 configfile.write('[paths]\n') |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
35 for k, v in paths.items(): |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
36 configfile.write('%s = %s\n' % (k, v)) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
37 configfile.close() |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
38 |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
39 confwd = hgwebdir(config) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
40 dictwd = hgwebdir(paths) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
41 |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
42 assert len(confwd.repos) == len(dictwd.repos), 'different numbers' |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
43 assert len(confwd.repos) == 9, 'expected 9 repos, found %d' % len(confwd.repos) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
44 |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
45 found = dict(confwd.repos) |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
46 for key, path in dictwd.repos: |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
47 assert key in found, 'repository %s was not found' % key |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
diff
changeset
|
48 assert found[key] == path, 'different paths for repo %s' % key |