annotate tests/test-rust-ancestor.py @ 51681:522b4d729e89

mmap: populate the mapping by default Without pre-population, accessing all data through a mmap can result in many pagefault, reducing performance significantly. If the mmap is prepopulated, the performance can no longer get slower than a full read. (See benchmark number below) In some cases were very few data is read, prepopulating can be overkill and slower than populating on access (through page fault). So that behavior can be controlled when the caller can pre-determine the best behavior. (See benchmark number below) In addition, testing with populating in a secondary thread yield great result combining the best of each approach. This might be implemented in later changesets. In all cases, using mmap has a great effect on memory usage when many processes run in parallel on the same machine. ### Benchmarks # What did I run A couple of month back I ran a large benchmark campaign to assess the impact of various approach for using mmap with the revlog (and other files), it highlighted a few benchmarks that capture the impact of the changes well. So to validate this change I checked the following: - log command displaying various revisions (read the changelog index) - log command displaying the patch of listed revisions (read the changelog index, the manifest index and a few files indexes) - unbundling a few revisions (read and write changelog, manifest and few files indexes, and walk the graph to update some cache) - pushing a few revisions (read and write changelog, manifest and few files indexes, walk the graph to update some cache, performs various accesses locally and remotely during discovery) Benchmarks were run using the default module policy (c+py) and the rust one. No significant difference were found between the two implementation, so we will present result using the default policy (unless otherwise specified). I ran them on a few repositories : - mercurial: a "public changeset only" copy of mercurial from 2018-08-01 using zstd compression and sparse-revlog - pypy: a copy of pypy from 2018-08-01 using zstd compression and sparse-revlog - netbeans: a copy of netbeans from 2018-08-01 using zstd compression and sparse-revlog - mozilla-try: a copy of mozilla-try from 2019-02-18 using zstd compression and sparse-revlog - mozilla-try persistent-nodemap: Same as the above but with a persistent nodemap. Used for the log --patch benchmark only # Results For the smaller repositories (mercurial, pypy), the impact of mmap is almost imperceptible, other cost dominating the operation. The impact of prepopulating is undiscernible in the benchmark we ran. For larger repositories the benchmark support explanation given above: On netbeans, the log can be about 1% faster without repopulation (for a difference < 100ms) but unbundle becomes a bit slower, even when small. ### data-env-vars.name = netbeans-2018-08-01-zstd-sparse-revlog # benchmark.name = hg.command.unbundle # benchmark.variants.issue6528 = disabled # benchmark.variants.reuse-external-delta-parent = yes # benchmark.variants.revs = any-1-extra-rev # benchmark.variants.source = unbundle # benchmark.variants.verbosity = quiet with-populate: 0.240157 no-populate: 0.265087 (+10.38%, +0.02) # benchmark.variants.revs = any-100-extra-rev with-populate: 1.459518 no-populate: 1.481290 (+1.49%, +0.02) ## benchmark.name = hg.command.push # benchmark.variants.explicit-rev = none # benchmark.variants.issue6528 = disabled # benchmark.variants.protocol = ssh # benchmark.variants.reuse-external-delta-parent = yes # benchmark.variants.revs = any-1-extra-rev with-populate: 0.771919 no-populate: 0.792025 (+2.60%, +0.02) # benchmark.variants.revs = any-100-extra-rev with-populate: 1.459518 no-populate: 1.481290 (+1.49%, +0.02) For mozilla-try, the "slow down" from pre-populate for small `hg log` is more visible, but still small in absolute time. (using rust value for the persistent nodemap value to be relevant). ### data-env-vars.name = mozilla-try-2019-02-18-ds2-pnm # benchmark.name = hg.command.log # bin-env-vars.hg.flavor = rust # benchmark.variants.patch = yes # benchmark.variants.limit-rev = 1 with-populate: 0.237813 no-populate: 0.229452 (-3.52%, -0.01) # benchmark.variants.limit-rev = 10 # benchmark.variants.patch = yes with-populate: 1.213578 no-populate: 1.205189 ### data-env-vars.name = mozilla-try-2019-02-18-zstd-sparse-revlog # benchmark.variants.limit-rev = 1000 # benchmark.variants.patch = no # benchmark.variants.rev = tip with-populate: 0.198607 no-populate: 0.195038 (-1.80%, -0.00) However pre-populating provide a significant boost on more complex operations like unbundle or push: ### data-env-vars.name = mozilla-try-2019-02-18-zstd-sparse-revlog # benchmark.name = hg.command.push # benchmark.variants.explicit-rev = none # benchmark.variants.issue6528 = disabled # benchmark.variants.protocol = ssh # benchmark.variants.reuse-external-delta-parent = yes # benchmark.variants.revs = any-1-extra-rev with-populate: 4.798632 no-populate: 4.953295 (+3.22%, +0.15) # benchmark.variants.revs = any-100-extra-rev with-populate: 4.903618 no-populate: 5.014963 (+2.27%, +0.11) ## benchmark.name = hg.command.unbundle # benchmark.variants.revs = any-1-extra-rev with-populate: 1.423411 no-populate: 1.585365 (+11.38%, +0.16) # benchmark.variants.revs = any-100-extra-rev with-populate: 1.537909 no-populate: 1.688489 (+9.79%, +0.15)
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 11 Apr 2024 00:02:07 +0200
parents 03fdd4d7b5bd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
1 import sys
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
2 import unittest
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
3
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 43944
diff changeset
4 from mercurial.node import wdirrev
41350
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
5
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
6 from mercurial.testing import revlog as revlogtesting
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
7
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
8 try:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
9 from mercurial import rustext
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
10
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
11 rustext.__name__ # trigger immediate actual import
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
12 except ImportError:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
13 rustext = None
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
14 else:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
15 # this would fail already without appropriate ancestor.__package__
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
16 from mercurial.rustext.ancestor import (
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
17 AncestorsIterator,
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
18 LazyAncestors,
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
19 MissingAncestors,
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
20 )
41694
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
21 from mercurial.rustext import dagop
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
22
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
23 try:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
24 from mercurial.cext import parsers as cparsers
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
25 except ImportError:
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
26 cparsers = None
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
27
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
28
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
29 @unittest.skipIf(
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
30 rustext is None,
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
31 'The Rust version of the "ancestor" module is not available. It is needed'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
32 ' for this test.',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
33 )
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
34 @unittest.skipIf(
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
35 rustext is None,
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
36 'The Rust or C version of the "parsers" module, which the "ancestor" module'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
37 ' relies on, is not available.',
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
38 )
51244
03fdd4d7b5bd rust-python-testing: separated base test classes
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51241
diff changeset
39 class rustancestorstest(revlogtesting.RustRevlogBasedTestBase):
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
40 """Test the correctness of binding to Rust code.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
41
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
42 This test is merely for the binding to Rust itself: extraction of
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
43 Python variable, giving back the results etc.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
44
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
45 It is not meant to test the algorithmic correctness of the operations
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
46 on ancestors it provides. Hence the very simple embedded index data is
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
47 good enough.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
48
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
49 Algorithmic correctness is asserted by the Rust unit tests.
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
50 """
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
51
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
52 def testiteratorrevlist(self):
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
53 idx = self.parserustindex()
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
54 # checking test assumption about the index binary data:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
55 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
56 {i: (r[5], r[6]) for i, r in enumerate(idx)},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
57 {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
58 )
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
59 ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
60 self.assertEqual([r for r in ait], [3, 2, 1, 0])
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
61
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
62 ait = AncestorsIterator(idx, [3], 0, False)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
63 self.assertEqual([r for r in ait], [2, 1, 0])
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
64
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
65 def testlazyancestors(self):
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
66 idx = self.parserustindex()
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
67 start_count = sys.getrefcount(idx) # should be 2 (see Python doc)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
68 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
69 {i: (r[5], r[6]) for i, r in enumerate(idx)},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
70 {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
71 )
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
72 lazy = LazyAncestors(idx, [3], 0, True)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
73 # we have two more references to the index:
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
74 # - in its inner iterator for __contains__ and __bool__
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
75 # - in the LazyAncestors instance itself (to spawn new iterators)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
76 self.assertEqual(sys.getrefcount(idx), start_count + 2)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
77
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
78 self.assertTrue(2 in lazy)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
79 self.assertTrue(bool(lazy))
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
80 self.assertEqual(list(lazy), [3, 2, 1, 0])
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
81 # a second time to validate that we spawn new iterators
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
82 self.assertEqual(list(lazy), [3, 2, 1, 0])
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
83
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
84 # now let's watch the refcounts closer
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
85 ait = iter(lazy)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
86 self.assertEqual(sys.getrefcount(idx), start_count + 3)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
87 del ait
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
88 self.assertEqual(sys.getrefcount(idx), start_count + 2)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
89 del lazy
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
90 self.assertEqual(sys.getrefcount(idx), start_count)
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
91
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
92 # let's check bool for an empty one
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
93 self.assertFalse(LazyAncestors(idx, [0], 0, False))
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
94
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
95 def testmissingancestors(self):
51240
59d81768ad6d rust-index: using `hg::index::Index` in MissingAncestors
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
96 idx = self.parserustindex()
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
97 missanc = MissingAncestors(idx, [1])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
98 self.assertTrue(missanc.hasbases())
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
99 self.assertEqual(missanc.missingancestors([3]), [2, 3])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
100 missanc.addbases({2})
41243
5257e6299d4c rust-cpython: set conversion for MissingAncestors.bases()
Georges Racinet <georges.racinet@octobus.net>
parents: 41188
diff changeset
101 self.assertEqual(missanc.bases(), {1, 2})
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
102 self.assertEqual(missanc.missingancestors([3]), [3])
41246
619ee4039bd4 rust: MissingAncestors.basesheads()
Georges Racinet <georges.racinet@octobus.net>
parents: 41243
diff changeset
103 self.assertEqual(missanc.basesheads(), {2})
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
104
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
105 def testmissingancestorsremove(self):
51240
59d81768ad6d rust-index: using `hg::index::Index` in MissingAncestors
Georges Racinet on incendie.racinet.fr <georges@racinet.fr>
parents: 51239
diff changeset
106 idx = self.parserustindex()
41188
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
107 missanc = MissingAncestors(idx, [1])
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
108 revs = {0, 1, 2, 3}
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
109 missanc.removeancestorsfrom(revs)
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
110 self.assertEqual(revs, {2, 3})
006c9ce486fa rust-cpython: bindings for MissingAncestors
Georges Racinet <georges.racinet@octobus.net>
parents: 41114
diff changeset
111
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
112 def testrefcount(self):
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
113 idx = self.parserustindex()
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
114 start_count = sys.getrefcount(idx)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
115
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
116 # refcount increases upon iterator init...
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
117 ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
118 self.assertEqual(sys.getrefcount(idx), start_count + 1)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
119 self.assertEqual(next(ait), 3)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
120
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
121 # and decreases once the iterator is removed
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
122 del ait
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
123 self.assertEqual(sys.getrefcount(idx), start_count)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
124
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
125 # and removing ref to the index after iterator init is no issue
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
126 ait = AncestorsIterator(idx, [3], 0, True)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
127 del idx
41114
b31a41f24864 rust-cpython: binding for LazyAncestors
Georges Racinet <gracinet@anybox.fr>
parents: 41053
diff changeset
128 self.assertEqual(list(ait), [3, 2, 1, 0])
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
129
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
130 # the index is not tracked by the GC, hence there is nothing more
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
131 # we can assert to check that it is properly deleted once its refcount
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
132 # drops to 0
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
133
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
134 def testgrapherror(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
135 data = (
43944
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
136 revlogtesting.data_non_inlined[: 64 + 27]
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
137 + b'\xf2'
8a8305f557d0 test: extract some generic data and utility from test-rust-ancestor.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
138 + revlogtesting.data_non_inlined[64 + 28 :]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
139 )
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
140 idx = self.parserustindex(data=data)
41053
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
141 with self.assertRaises(rustext.GraphError) as arc:
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
142 AncestorsIterator(idx, [1], -1, False)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
143 exc = arc.exception
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
144 self.assertIsInstance(exc, ValueError)
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
145 # rust-cpython issues appropriate str instances for Python 2 and 3
d9f439fcdb4c rust-cpython: binding for AncestorsIterator
Georges Racinet <gracinet@anybox.fr>
parents: 40968
diff changeset
146 self.assertEqual(exc.args, ('ParentOutOfRange', 1))
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
147
41350
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
148 def testwdirunsupported(self):
ab0d762d89ef rust-cpython: raising error.WdirUnsupported
Georges Racinet <georges.racinet@octobus.net>
parents: 41246
diff changeset
149 # trying to access ancestors of the working directory raises
51239
7eea2e4109ae rust-index: using the `hg::index::Index` in ancestors iterator and lazy set
Georges Racinet <georges.racinet@octobus.net>
parents: 50979
diff changeset
150 idx = self.parserustindex()
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 48875
diff changeset
151 with self.assertRaises(rustext.GraphError) as arc:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 43944
diff changeset
152 list(AncestorsIterator(idx, [wdirrev], -1, False))
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
153
50979
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 48875
diff changeset
154 exc = arc.exception
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 48875
diff changeset
155 self.assertIsInstance(exc, ValueError)
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 48875
diff changeset
156 # rust-cpython issues appropriate str instances for Python 2 and 3
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 48875
diff changeset
157 self.assertEqual(exc.args, ('InvalidRevision', wdirrev))
4c5f6e95df84 rust: make `Revision` a newtype
Raphaël Gomès <rgomes@octobus.net>
parents: 48875
diff changeset
158
41694
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
159 def testheadrevs(self):
51241
578c049f0408 rust-index: using `hg::index::Index` in `hg-cpython::dagops`
Georges Racinet <georges.racinet@octobus.net>
parents: 51240
diff changeset
160 idx = self.parserustindex()
41694
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
161 self.assertEqual(dagop.headrevs(idx, [1, 2, 3]), {3})
0c7b353ce100 rust-cpython: binding for headrevs()
Georges Racinet <georges.racinet@octobus.net>
parents: 41350
diff changeset
162
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
163
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
164 if __name__ == '__main__':
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
165 import silenttestrunner
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41694
diff changeset
166
40968
74f41329bf55 rust-cpython: testing the bindings from Python
Georges Racinet <gracinet@anybox.fr>
parents:
diff changeset
167 silenttestrunner.main(__name__)