From a4807d6e0bdabc43410c40cd2163ffe8056694d7 Mon Sep 17 00:00:00 2001 From: Xavier Deguillard Date: Fri, 26 Apr 2019 11:21:02 -0700 Subject: [PATCH] remotefilelog: add a test to verify the behavior of refresh Summary: When `remotefilelog.fetchpacks` is enabled, an automatic repack will be triggered on refresh. Let's add a test to verify this behavior. Reviewed By: singhsrb Differential Revision: D15095200 fbshipit-source-id: 89c0a98925e4e53413cf9ea1b1862859c370e12a --- tests/test-fb-hgext-remotefilelog-datapack.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test-fb-hgext-remotefilelog-datapack.py b/tests/test-fb-hgext-remotefilelog-datapack.py index 8660b4ee78..1c7449b927 100755 --- a/tests/test-fb-hgext-remotefilelog-datapack.py +++ b/tests/test-fb-hgext-remotefilelog-datapack.py @@ -319,6 +319,53 @@ class datapacktestsbase(object): self.assertEquals(randomchain.index(revision) + 1, len(chain)) + def testInlineRepack(self): + """Verify that when fetchpacks is enabled, and the number of packfiles + is over DEFAULTCACHESIZE, the refresh operation will trigger a repack, + reducing the number of packfiles in the store. + """ + packdir = self.makeTempDir() + + numpacks = 20 + revisionsperpack = 100 + + for i in range(numpacks): + chain = [] + revision = (str(i), self.getFakeHash(), nullid, "content") + + for _ in range(revisionsperpack): + chain.append(revision) + revision = (str(i), self.getFakeHash(), revision[1], self.getFakeHash()) + + self.createPack(chain, packdir) + + packreader = self.datapackreader + + class testdatapackstore(datapackstore): + DEFAULTCACHESIZE = numpacks / 2 + + def getpack(self, path): + return packreader(path) + + store = testdatapackstore(uimod.ui(), packdir, self.iscdatapack) + + # The first refresh should populate all the packfiles. + store.refresh() + self.assertEquals(len(store.packs), testdatapackstore.DEFAULTCACHESIZE) + + # Each packfile is made up of 2 files: the data, and the index + self.assertEquals(len(os.listdir(packdir)), numpacks * 2) + + store.markforrefresh() + + # The second one should repack all the packfiles into one. + store.fetchpacksenabled = True + store.refresh() + self.assertEquals(len(store.packs), 1) + + # There should only be 2 files: the packfile, and the index + self.assertEquals(len(os.listdir(packdir)), 2) + def testCorruptPackHandling(self): """Test that the pack store deletes corrupt packs.""" # There's a bug in cdatapack right now that causes it to return bad data