tests/test-dirs.py
author Georges Racinet <georges.racinet@octobus.net>
Tue, 20 Jul 2021 17:20:19 +0200
changeset 47909 de2e04fe4897
parent 43571 c21aca51b392
child 48043 627cd8f33db0
permissions -rw-r--r--
hgwebdir: avoid systematic full garbage collection Forcing a systematic full garbage collection upon each request can serioulsy harm performance. This is reported as https://bz.mercurial-scm.org/show_bug.cgi?id=6075 With this change we're performing the full collection according to a new setting, `experimental.web.full-garbage-collection-rate`. The default value is 1, which doesn't change the behavior and will allow us to test on real use cases. If the value is 0, no full garbage collection occurs. Regardless of the value of the setting, a partial garbage collection still occurs upon each request (not attempting to collect objects from the oldest generation). This should be enough to take care of reference cycles that have been created by the last request (assessment of this requires changing the setting, not to be 1). In my experience chasing memory leaks in Mercurial servers, the full collection never reclaimed any memory, but this is with Python 3 and biased towards small repositories. On the other hand, as explained in the Python developer docs [1], frequent full collections are very harmful in terms of performance if lots of objects survive the collection, and hence stay in the oldest generation. Note that `gc.collect()` is indeed trying to collect the oldest generation [2]. This happens usually in two cases: - unwanted lingering objects (i.e., an actual memory leak that the GC cannot do anything about). Sadly, we have lots of those these days. - desireable long-term objects, typically in caches (not inner caches carried by repositories, which should be collected with them). This is a subject of interest for the Heptapod project. In short, the flat rate that this change still permits is probably a bad idea in most cases, and the default value can be tweaked later on (or even be set to 0) according to experiments in the wild. The test is inspired from test-hgwebdir-paths.py [1] https://devguide.python.org/garbage_collector/#collecting-the-oldest-generation [2] https://docs.python.org/3/library/gc.html#gc.collect Differential Revision: https://phab.mercurial-scm.org/D11204
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43542
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
from __future__ import absolute_import
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
import unittest
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
import silenttestrunner
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43542
diff changeset
     7
from mercurial import pathutil
43542
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
class dirstests(unittest.TestCase):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
    def testdirs(self):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
        for case, want in [
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
            (b'a/a/a', [b'a', b'a/a', b'']),
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
            (b'alpha/beta/gamma', [b'', b'alpha', b'alpha/beta']),
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
        ]:
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43542
diff changeset
    16
            d = pathutil.dirs({})
43542
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
            d.addpath(case)
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
            self.assertEqual(sorted(d), sorted(want))
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
    def testinvalid(self):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
        with self.assertRaises(ValueError):
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43542
diff changeset
    22
            d = pathutil.dirs({})
43542
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
            d.addpath(b'a//b')
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
if __name__ == '__main__':
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
    silenttestrunner.main(__name__)