comparison tests/artifacts/scripts/generate-churning-bundle.py @ 52471:24c3b3dbab08

test-sparse-revlog: make the large bundle generation more robust and useful We do the following: - adding a `--lazy` flag that skip the bundle generation if it already has the right content. - adding a `--validate` flag that make sure the generated bundle match the expected content Generate it on the fly with all this flag during the tests.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 04 Dec 2024 15:05:56 +0100
parents 83f87912c5e0
children 7e5ed1e80913
comparison
equal deleted inserted replaced
52470:83f87912c5e0 52471:24c3b3dbab08
12 # 12 #
13 # The repository update a single "large" file with many updates. One fixed part 13 # The repository update a single "large" file with many updates. One fixed part
14 # of the files always get updated while the rest of the lines get updated over 14 # of the files always get updated while the rest of the lines get updated over
15 # time. This update happens over many topological branches, some getting merged 15 # time. This update happens over many topological branches, some getting merged
16 # back. 16 # back.
17 #
18 # --lazy will skip generating the file if one exist with the right content
19 # already.
20 # --validate make sure the generated bundle has the expected content.
17 21
18 22
19 import hashlib 23 import hashlib
20 import os 24 import os
21 import shutil 25 import shutil
249 date=(0, 0), 253 date=(0, 0),
250 ) 254 )
251 nodemap[idx] = repo.commitctx(mc) 255 nodemap[idx] = repo.commitctx(mc)
252 256
253 257
254 def run(target): 258 def compute_md5(target):
259 with open(target, 'rb') as bundle:
260 data = bundle.read()
261 return hashlib.md5(data).hexdigest()
262
263
264 def write_md5(target, md5):
265 with open(target + '.md5', 'wb') as md5file:
266 md5file.write(md5.encode('ascii') + b'\n')
267
268
269 def read_md5(target):
270 with open(target + '.md5', 'rb') as md5file:
271 return md5file.read().strip().decode('ascii')
272
273
274 def up_to_date_target(target):
275 """return true if the file already exist at the right"""
276 try:
277 found = compute_md5(target)
278 expected = read_md5(target)
279 except OSError:
280 return False
281 return found == expected
282
283
284 def run(target, validate=False):
255 tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-') 285 tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-')
256 try: 286 try:
257 os.chdir(tmpdir) 287 os.chdir(tmpdir)
258 hg( 288 hg(
259 'init', 289 'init',
260 '--config', 290 '--config',
261 'format.maxchainlen=%d' % NB_CHANGESET, 291 'format.maxchainlen=%d' % NB_CHANGESET,
262 ) 292 )
263 write_repo(tmpdir) 293 write_repo(tmpdir)
264 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') 294 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1')
265 with open(target, 'rb') as bundle: 295 digest = compute_md5(target)
266 data = bundle.read() 296 if not validate:
267 digest = hashlib.md5(data).hexdigest() 297 write_md5(target, digest)
268 with open(target + '.md5', 'wb') as md5file: 298 else:
269 md5file.write(digest.encode('ascii') + b'\n') 299 expected = read_md5(target)
270 if sys.stdout.isatty(): 300 if expected != digest:
271 print('bundle generated at "%s" md5: %s' % (target, digest)) 301 msg = "bundle generated does not match the expected content\n"
272 302 msg += " expected: %s\n" % expected
303 msg += " got: %s" % digest
304 print(msg, file=sys.stderr)
305 return 1
273 finally: 306 finally:
274 shutil.rmtree(tmpdir) 307 shutil.rmtree(tmpdir)
275 return 0 308 return 0
276 309
277 310
278 if __name__ == '__main__': 311 if __name__ == '__main__':
279 orig = os.path.realpath(os.path.dirname(sys.argv[0])) 312 orig = os.path.realpath(os.path.dirname(sys.argv[0]))
280 target = os.path.join(orig, os.pardir, 'cache', BUNDLE_NAME) 313 target = os.path.join(orig, os.pardir, 'cache', BUNDLE_NAME)
281 sys.exit(run(target)) 314 lazy = '--lazy' in sys.argv[1:]
315 validate = '--validate' in sys.argv[1:]
316 if lazy and up_to_date_target(target):
317 sys.exit(0)
318 sys.exit(run(target, validate=validate))