##// END OF EJS Templates
test-sparse-revlog: make the large bundle generation more robust and useful...
marmoute -
r53337:24c3b3db default
parent child Browse files
Show More
@@ -14,6 +14,10
14 14 # of the files always get updated while the rest of the lines get updated over
15 15 # time. This update happens over many topological branches, some getting merged
16 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 23 import hashlib
@@ -251,7 +255,33 def write_repo(path):
251 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 285 tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-')
256 286 try:
257 287 os.chdir(tmpdir)
@@ -262,14 +292,17 def run(target):
262 292 )
263 293 write_repo(tmpdir)
264 294 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1')
265 with open(target, 'rb') as bundle:
266 data = bundle.read()
267 digest = hashlib.md5(data).hexdigest()
268 with open(target + '.md5', 'wb') as md5file:
269 md5file.write(digest.encode('ascii') + b'\n')
270 if sys.stdout.isatty():
271 print('bundle generated at "%s" md5: %s' % (target, digest))
272
295 digest = compute_md5(target)
296 if not validate:
297 write_md5(target, digest)
298 else:
299 expected = read_md5(target)
300 if expected != digest:
301 msg = "bundle generated does not match the expected content\n"
302 msg += " expected: %s\n" % expected
303 msg += " got: %s" % digest
304 print(msg, file=sys.stderr)
305 return 1
273 306 finally:
274 307 shutil.rmtree(tmpdir)
275 308 return 0
@@ -278,4 +311,8 def run(target):
278 311 if __name__ == '__main__':
279 312 orig = os.path.realpath(os.path.dirname(sys.argv[0]))
280 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))
@@ -11,28 +11,32 repeatedly while some of it changes rare
11 11
12 12 $ bundlepath="$TESTDIR/artifacts/cache/big-file-churn.hg"
13 13
14 #if pure
14 15 $ expectedhash=`cat "$bundlepath".md5`
15
16 #if slow
17
18 $ if [ ! -f "$bundlepath" ]; then
19 > "$TESTDIR"/artifacts/scripts/generate-churning-bundle.py > /dev/null
20 > fi
21
22 #else
23
24 16 $ if [ ! -f "$bundlepath" ]; then
25 17 > echo 'skipped: missing artifact, run "'"$TESTDIR"'/artifacts/scripts/generate-churning-bundle.py"'
26 18 > exit 80
27 19 > fi
28
29 #endif
30
31 20 $ currenthash=`f -M "$bundlepath" | cut -d = -f 2`
32 21 $ if [ "$currenthash" != "$expectedhash" ]; then
33 22 > echo 'skipped: outdated artifact, md5 "'"$currenthash"'" expected "'"$expectedhash"'" run "'"$TESTDIR"'/artifacts/scripts/generate-churning-bundle.py"'
34 23 > exit 80
35 24 > fi
25 #else
26
27 #if slow
28 $ LAZY_GEN=""
29
30 #else
31 $ LAZY_GEN="--lazy"
32 #endif
33
34 #endif
35
36 If the validation fails, either something is broken or the expected md5 need updating.
37 To update the md5, invoke the script without --validate
38
39 $ "$TESTDIR"/artifacts/scripts/generate-churning-bundle.py --validate $LAZY_GEN > /dev/null
36 40
37 41 $ cat >> $HGRCPATH << EOF
38 42 > [format]
General Comments 0
You need to be logged in to leave comments. Login now