# HG changeset patch # User Pierre-Yves David # Date 2024-12-04 14:05:56 # Node ID 24c3b3dbab089959302e932931c3fa195198512d # Parent 83f87912c5e09f1980475f1cf15dbbed3aef2053 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. diff --git a/tests/artifacts/scripts/generate-churning-bundle.py b/tests/artifacts/scripts/generate-churning-bundle.py --- a/tests/artifacts/scripts/generate-churning-bundle.py +++ b/tests/artifacts/scripts/generate-churning-bundle.py @@ -14,6 +14,10 @@ # of the files always get updated while the rest of the lines get updated over # time. This update happens over many topological branches, some getting merged # back. +# +# --lazy will skip generating the file if one exist with the right content +# already. +# --validate make sure the generated bundle has the expected content. import hashlib @@ -251,7 +255,33 @@ def write_repo(path): nodemap[idx] = repo.commitctx(mc) -def run(target): +def compute_md5(target): + with open(target, 'rb') as bundle: + data = bundle.read() + return hashlib.md5(data).hexdigest() + + +def write_md5(target, md5): + with open(target + '.md5', 'wb') as md5file: + md5file.write(md5.encode('ascii') + b'\n') + + +def read_md5(target): + with open(target + '.md5', 'rb') as md5file: + return md5file.read().strip().decode('ascii') + + +def up_to_date_target(target): + """return true if the file already exist at the right""" + try: + found = compute_md5(target) + expected = read_md5(target) + except OSError: + return False + return found == expected + + +def run(target, validate=False): tmpdir = tempfile.mkdtemp(prefix='tmp-hg-test-big-file-bundle-') try: os.chdir(tmpdir) @@ -262,14 +292,17 @@ def run(target): ) write_repo(tmpdir) hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') - with open(target, 'rb') as bundle: - data = bundle.read() - digest = hashlib.md5(data).hexdigest() - with open(target + '.md5', 'wb') as md5file: - md5file.write(digest.encode('ascii') + b'\n') - if sys.stdout.isatty(): - print('bundle generated at "%s" md5: %s' % (target, digest)) - + digest = compute_md5(target) + if not validate: + write_md5(target, digest) + else: + expected = read_md5(target) + if expected != digest: + msg = "bundle generated does not match the expected content\n" + msg += " expected: %s\n" % expected + msg += " got: %s" % digest + print(msg, file=sys.stderr) + return 1 finally: shutil.rmtree(tmpdir) return 0 @@ -278,4 +311,8 @@ def run(target): if __name__ == '__main__': orig = os.path.realpath(os.path.dirname(sys.argv[0])) target = os.path.join(orig, os.pardir, 'cache', BUNDLE_NAME) - sys.exit(run(target)) + lazy = '--lazy' in sys.argv[1:] + validate = '--validate' in sys.argv[1:] + if lazy and up_to_date_target(target): + sys.exit(0) + sys.exit(run(target, validate=validate)) diff --git a/tests/test-sparse-revlog.t b/tests/test-sparse-revlog.t --- a/tests/test-sparse-revlog.t +++ b/tests/test-sparse-revlog.t @@ -11,28 +11,32 @@ repeatedly while some of it changes rare $ bundlepath="$TESTDIR/artifacts/cache/big-file-churn.hg" +#if pure $ expectedhash=`cat "$bundlepath".md5` - -#if slow - - $ if [ ! -f "$bundlepath" ]; then - > "$TESTDIR"/artifacts/scripts/generate-churning-bundle.py > /dev/null - > fi - -#else - $ if [ ! -f "$bundlepath" ]; then > echo 'skipped: missing artifact, run "'"$TESTDIR"'/artifacts/scripts/generate-churning-bundle.py"' > exit 80 > fi - -#endif - $ currenthash=`f -M "$bundlepath" | cut -d = -f 2` $ if [ "$currenthash" != "$expectedhash" ]; then > echo 'skipped: outdated artifact, md5 "'"$currenthash"'" expected "'"$expectedhash"'" run "'"$TESTDIR"'/artifacts/scripts/generate-churning-bundle.py"' > exit 80 > fi +#else + +#if slow + $ LAZY_GEN="" + +#else + $ LAZY_GEN="--lazy" +#endif + +#endif + +If the validation fails, either something is broken or the expected md5 need updating. +To update the md5, invoke the script without --validate + + $ "$TESTDIR"/artifacts/scripts/generate-churning-bundle.py --validate $LAZY_GEN > /dev/null $ cat >> $HGRCPATH << EOF > [format]