annotate tests/test-remotefilelog-datapack.py @ 44311:2b72c4ff8ed1

nodemap: use an intermediate "docket" file to carry small metadata This intermediate file will make mmapping, transaction and content validation easier. (Most of this usefulness will arrive gradually in later changeset). In particular it will become very useful to append new data are the end of raw file instead of rewriting on the file on each transaction. See in code comments for details. Differential Revision: https://phab.mercurial-scm.org/D7838
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Jan 2020 15:47:50 +0100
parents 37458d8b0c1e
children dca4b5da417d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
1 #!/usr/bin/env python
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
2 from __future__ import absolute_import, print_function
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
3
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
4 import hashlib
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
5 import os
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
6 import random
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
7 import shutil
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
8 import stat
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
9 import struct
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
10 import sys
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
11 import tempfile
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
12 import time
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
13 import unittest
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
14
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
15 import silenttestrunner
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
16
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
17 # Load the local remotefilelog, not the system one
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
18 sys.path[0:0] = [os.path.join(os.path.dirname(__file__), '..')]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
19 from mercurial.node import nullid
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
20 from mercurial import (
41254
2888d12b80a6 tests: fix up uses of xrange in remotefilelog tests for py3
Augie Fackler <augie@google.com>
parents: 40506
diff changeset
21 pycompat,
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
22 ui as uimod,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
23 )
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
24 from hgext.remotefilelog import (
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
25 basepack,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
26 constants,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
27 datapack,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
28 )
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
29
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
30
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
31 class datapacktestsbase(object):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
32 def __init__(self, datapackreader, paramsavailable):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
33 self.datapackreader = datapackreader
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
34 self.paramsavailable = paramsavailable
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
35
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
36 def setUp(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
37 self.tempdirs = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
38
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
39 def tearDown(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
40 for d in self.tempdirs:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
41 shutil.rmtree(d)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
42
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
43 def makeTempDir(self):
41473
90b3898cf0db tests: various Python 3 ports for test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41472
diff changeset
44 tempdir = pycompat.bytestr(tempfile.mkdtemp())
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
45 self.tempdirs.append(tempdir)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
46 return tempdir
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
47
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
48 def getHash(self, content):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
49 return hashlib.sha1(content).digest()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
50
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
51 def getFakeHash(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
52 return b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
53 pycompat.bytechr(random.randint(0, 255)) for _ in range(20)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
54 )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
55
40506
10c10da14c5d remotefilelog: bump pack file formats to version 2
Augie Fackler <augie@google.com>
parents: 40495
diff changeset
56 def createPack(self, revisions=None, packdir=None):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
57 if revisions is None:
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
58 revisions = [(b"filename", self.getFakeHash(), nullid, b"content")]
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
59
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
60 if packdir is None:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
61 packdir = self.makeTempDir()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
62
40506
10c10da14c5d remotefilelog: bump pack file formats to version 2
Augie Fackler <augie@google.com>
parents: 40495
diff changeset
63 packer = datapack.mutabledatapack(uimod.ui(), packdir, version=2)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
64
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
65 for args in revisions:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
66 filename, node, base, content = args[0:4]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
67 # meta is optional
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
68 meta = None
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
69 if len(args) > 4:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
70 meta = args[4]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
71 packer.add(filename, node, base, content, metadata=meta)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
72
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
73 path = packer.close()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
74 return self.datapackreader(path)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
75
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
76 def _testAddSingle(self, content):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
77 """Test putting a simple blob into a pack and reading it out.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
78 """
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
79 filename = b"foo"
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
80 node = self.getHash(content)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
81
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
82 revisions = [(filename, node, nullid, content)]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
83 pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
84 if self.paramsavailable:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
85 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
86 pack.params.fanoutprefix, basepack.SMALLFANOUTPREFIX
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
87 )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
88
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
89 chain = pack.getdeltachain(filename, node)
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
90 self.assertEqual(content, chain[0][4])
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
91
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
92 def testAddSingle(self):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
93 self._testAddSingle(b'')
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
94
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
95 def testAddSingleEmpty(self):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
96 self._testAddSingle(b'abcdef')
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
97
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
98 def testAddMultiple(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
99 """Test putting multiple unrelated blobs into a pack and reading them
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
100 out.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
101 """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
102 revisions = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
103 for i in range(10):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
104 filename = b"foo%d" % i
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
105 content = b"abcdef%d" % i
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
106 node = self.getHash(content)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
107 revisions.append((filename, node, self.getFakeHash(), content))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
108
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
109 pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
110
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
111 for filename, node, base, content in revisions:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
112 entry = pack.getdelta(filename, node)
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
113 self.assertEqual((content, filename, base, {}), entry)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
114
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
115 chain = pack.getdeltachain(filename, node)
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
116 self.assertEqual(content, chain[0][4])
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
117
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
118 def testAddDeltas(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
119 """Test putting multiple delta blobs into a pack and read the chain.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
120 """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
121 revisions = []
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
122 filename = b"foo"
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
123 lastnode = nullid
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
124 for i in range(10):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
125 content = b"abcdef%d" % i
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
126 node = self.getHash(content)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
127 revisions.append((filename, node, lastnode, content))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
128 lastnode = node
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
129
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
130 pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
131
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
132 entry = pack.getdelta(filename, revisions[0][1])
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
133 realvalue = (revisions[0][3], filename, revisions[0][2], {})
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
134 self.assertEqual(entry, realvalue)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
135
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
136 # Test that the chain for the final entry has all the others
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
137 chain = pack.getdeltachain(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
138 for i in range(10):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
139 content = b"abcdef%d" % i
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
140 self.assertEqual(content, chain[-i - 1][4])
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
141
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
142 def testPackMany(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
143 """Pack many related and unrelated objects.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
144 """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
145 # Build a random pack file
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
146 revisions = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
147 blobs = {}
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
148 random.seed(0)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
149 for i in range(100):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
150 filename = b"filename-%d" % i
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
151 filerevs = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
152 for j in range(random.randint(1, 100)):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
153 content = b"content-%d" % j
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
154 node = self.getHash(content)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
155 lastnode = nullid
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
156 if len(filerevs) > 0:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
157 lastnode = filerevs[random.randint(0, len(filerevs) - 1)]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
158 filerevs.append(node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
159 blobs[(filename, node, lastnode)] = content
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
160 revisions.append((filename, node, lastnode, content))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
161
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
162 pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
163
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
164 # Verify the pack contents
41472
6309ce86fa82 tests: use items() in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41471
diff changeset
165 for (filename, node, lastnode), content in sorted(blobs.items()):
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
166 chain = pack.getdeltachain(filename, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
167 for entry in chain:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
168 expectedcontent = blobs[(entry[0], entry[1], entry[3])]
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
169 self.assertEqual(entry[4], expectedcontent)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
170
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
171 def testPackMetadata(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
172 revisions = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
173 for i in range(100):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
174 filename = b'%d.txt' % i
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
175 content = b'put-something-here \n' * i
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
176 node = self.getHash(content)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
177 meta = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
178 constants.METAKEYFLAG: i ** 4,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
179 constants.METAKEYSIZE: len(content),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
180 b'Z': b'random_string',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
181 b'_': b'\0' * i,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
182 }
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
183 revisions.append((filename, node, nullid, content, meta))
40506
10c10da14c5d remotefilelog: bump pack file formats to version 2
Augie Fackler <augie@google.com>
parents: 40495
diff changeset
184 pack = self.createPack(revisions)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
185 for name, node, x, content, origmeta in revisions:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
186 parsedmeta = pack.getmeta(name, node)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
187 # flag == 0 should be optimized out
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
188 if origmeta[constants.METAKEYFLAG] == 0:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
189 del origmeta[constants.METAKEYFLAG]
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
190 self.assertEqual(parsedmeta, origmeta)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
191
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
192 def testGetMissing(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
193 """Test the getmissing() api.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
194 """
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
195 revisions = []
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
196 filename = b"foo"
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
197 lastnode = nullid
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
198 for i in range(10):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
199 content = b"abcdef%d" % i
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
200 node = self.getHash(content)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
201 revisions.append((filename, node, lastnode, content))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
202 lastnode = node
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
203
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
204 pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
205
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
206 missing = pack.getmissing([(b"foo", revisions[0][1])])
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
207 self.assertFalse(missing)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
208
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
209 missing = pack.getmissing(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
210 [(b"foo", revisions[0][1]), (b"foo", revisions[1][1])]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
211 )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
212 self.assertFalse(missing)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
213
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
214 fakenode = self.getFakeHash()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
215 missing = pack.getmissing(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
216 [(b"foo", revisions[0][1]), (b"foo", fakenode)]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
217 )
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
218 self.assertEqual(missing, [(b"foo", fakenode)])
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
219
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
220 def testAddThrows(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
221 pack = self.createPack()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
222
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
223 try:
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
224 pack.add(b'filename', nullid, b'contents')
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
225 self.assertTrue(False, "datapack.add should throw")
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
226 except RuntimeError:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
227 pass
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
228
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
229 def testBadVersionThrows(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
230 pack = self.createPack()
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
231 path = pack.path + b'.datapack'
41473
90b3898cf0db tests: various Python 3 ports for test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41472
diff changeset
232 with open(path, 'rb') as f:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
233 raw = f.read()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
234 raw = struct.pack('!B', 255) + raw[1:]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
235 os.chmod(path, os.stat(path).st_mode | stat.S_IWRITE)
41473
90b3898cf0db tests: various Python 3 ports for test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41472
diff changeset
236 with open(path, 'wb+') as f:
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
237 f.write(raw)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
238
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
239 try:
43990
37458d8b0c1e tests: drop unused local variable assignments in remotefilelog
Matt Harbison <matt_harbison@yahoo.com>
parents: 43076
diff changeset
240 self.datapackreader(pack.path)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
241 self.assertTrue(False, "bad version number should have thrown")
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
242 except RuntimeError:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
243 pass
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
244
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
245 def testMissingDeltabase(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
246 fakenode = self.getFakeHash()
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
247 revisions = [(b"filename", fakenode, self.getFakeHash(), b"content")]
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
248 pack = self.createPack(revisions)
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
249 chain = pack.getdeltachain(b"filename", fakenode)
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
250 self.assertEqual(len(chain), 1)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
251
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
252 def testLargePack(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
253 """Test creating and reading from a large pack with over X entries.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
254 This causes it to use a 2^16 fanout table instead."""
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
255 revisions = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
256 blobs = {}
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
257 total = basepack.SMALLFANOUTCUTOFF + 1
41254
2888d12b80a6 tests: fix up uses of xrange in remotefilelog tests for py3
Augie Fackler <augie@google.com>
parents: 40506
diff changeset
258 for i in pycompat.xrange(total):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
259 filename = b"filename-%d" % i
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
260 content = filename
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
261 node = self.getHash(content)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
262 blobs[(filename, node)] = content
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
263 revisions.append((filename, node, nullid, content))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
264
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
265 pack = self.createPack(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
266 if self.paramsavailable:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
267 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
268 pack.params.fanoutprefix, basepack.LARGEFANOUTPREFIX
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
269 )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
270
41472
6309ce86fa82 tests: use items() in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41471
diff changeset
271 for (filename, node), content in blobs.items():
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
272 actualcontent = pack.getdeltachain(filename, node)[0][4]
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
273 self.assertEqual(actualcontent, content)
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
274
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
275 def testPacksCache(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
276 """Test that we remember the most recent packs while fetching the delta
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
277 chain."""
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
278
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
279 packdir = self.makeTempDir()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
280 deltachains = []
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
281
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
282 numpacks = 10
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
283 revisionsperpack = 100
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
284
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
285 for i in range(numpacks):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
286 chain = []
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
287 revision = (b'%d' % i, self.getFakeHash(), nullid, b"content")
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
288
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
289 for _ in range(revisionsperpack):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
290 chain.append(revision)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
291 revision = (
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
292 b'%d' % i,
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
293 self.getFakeHash(),
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
294 revision[1],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
295 self.getFakeHash(),
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
296 )
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
297
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
298 self.createPack(chain, packdir)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
299 deltachains.append(chain)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
300
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
301 class testdatapackstore(datapack.datapackstore):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
302 # Ensures that we are not keeping everything in the cache.
41527
eb37d95cc486 py3: use integer division instead of `int(...)` call
Boris Feld <boris.feld@octobus.net>
parents: 41474
diff changeset
303 DEFAULTCACHESIZE = numpacks // 2
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
304
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
305 store = testdatapackstore(uimod.ui(), packdir)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
306
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
307 random.shuffle(deltachains)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
308 for randomchain in deltachains:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
309 revision = random.choice(randomchain)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
310 chain = store.getdeltachain(revision[0], revision[1])
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
311
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
312 mostrecentpack = next(iter(store.packs), None)
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
313 self.assertEqual(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
314 mostrecentpack.getdeltachain(revision[0], revision[1]), chain
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
315 )
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
316
41321
724b4606528e tests: use assertEqual()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41268
diff changeset
317 self.assertEqual(randomchain.index(revision) + 1, len(chain))
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
318
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
319 # perf test off by default since it's slow
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
320 def _testIndexPerf(self):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
321 random.seed(0)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
322 print("Multi-get perf test")
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
323 packsizes = [
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
324 100,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
325 10000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
326 100000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
327 500000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
328 1000000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
329 3000000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
330 ]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
331 lookupsizes = [
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
332 10,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
333 100,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
334 1000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
335 10000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
336 100000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
337 1000000,
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
338 ]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
339 for packsize in packsizes:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
340 revisions = []
41254
2888d12b80a6 tests: fix up uses of xrange in remotefilelog tests for py3
Augie Fackler <augie@google.com>
parents: 40506
diff changeset
341 for i in pycompat.xrange(packsize):
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
342 filename = b"filename-%d" % i
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
343 content = b"content-%d" % i
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
344 node = self.getHash(content)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
345 revisions.append((filename, node, nullid, content))
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
346
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
347 path = self.createPack(revisions).path
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
348
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
349 # Perf of large multi-get
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
350 import gc
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
351
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
352 gc.disable()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
353 pack = self.datapackreader(path)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
354 for lookupsize in lookupsizes:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
355 if lookupsize > packsize:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
356 continue
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
357 random.shuffle(revisions)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
358 findnodes = [(rev[0], rev[1]) for rev in revisions]
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
359
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
360 start = time.time()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
361 pack.getmissing(findnodes[:lookupsize])
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
362 elapsed = time.time() - start
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
363 print(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
364 "%s pack %d lookups = %0.04f"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
365 % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
366 ('%d' % packsize).rjust(7),
41471
268325697a47 tests: use bytes and %d formatting in test-remotefilelog-datapack.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41321
diff changeset
367 ('%d' % lookupsize).rjust(7),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
368 elapsed,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
369 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
370 )
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
371
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
372 print("")
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
373 gc.enable()
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
374
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
375 # The perf test is meant to produce output, so we always fail the test
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
376 # so the user sees the output.
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
377 raise RuntimeError("perf test always fails")
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
378
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
379
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
380 class datapacktests(datapacktestsbase, unittest.TestCase):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
381 def __init__(self, *args, **kwargs):
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
382 datapacktestsbase.__init__(self, datapack.datapack, True)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
383 unittest.TestCase.__init__(self, *args, **kwargs)
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
384
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
385
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
386 # TODO:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
387 # datapack store:
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
388 # - getmissing
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
389 # - GC two packs into one
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
390
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
391 if __name__ == '__main__':
41268
878084a495ef tests: also skip remotefilelog *.py tests on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 41254
diff changeset
392 if pycompat.iswindows:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41527
diff changeset
393 sys.exit(80) # Skip on Windows
40495
3a333a582d7b remotefilelog: import pruned-down remotefilelog extension from hg-experimental
Augie Fackler <augie@google.com>
parents:
diff changeset
394 silenttestrunner.main(__name__)