sapling/tests/test-sampling.t
Laurent Charignon e9b8bf6ba5 fastmanifest: fix sampling
Summary:
This patch fixes various things around the sampling extension to
match what our wrapper expects to see. See detail in the test.

Test Plan:
        lcharignon@XXX fbsource cat ~/.hgrc
        ...
        [extensions]
        sampling=
        [sampling]
        key.fastmanifest-cachehitratio=table_blah
        key.fastmanifest-trigger=table_blah
        filepath=/dev/shm/samppath


        lcharignon@XXX fbsource hhg book foo

        lcharignon@XXX fbsource cat /dev/shm/samppath
        {"category": "table_blah", "data": {"source": "bookmark", "metrics_type":
        "fastmanifest-trigger"}}\0{"category": "table_blah", "data": {"ratio": -1, "metrics_type":
        "fastmanifest-cachehitratio"}}\0

Reviewers: ttung, durham

Differential Revision: https://phabricator.intern.facebook.com/D3466719
2016-06-21 17:07:55 -07:00

61 lines
1.7 KiB
Perl

Setup
$ PYTHONPATH=$TESTDIR/..:$PYTHONPATH
$ export PYTHONPATH
$ mkcommit() {
> echo "$1" > "$1"
> hg add "$1"
> echo "add $1" > msg
> echo "" >> msg
> hg ci -l msg
> }
Init the repo
$ hg init testrepo
$ cd testrepo
$ mkcommit a
Create an extension that logs every commit and also call repo.revs twice
Create an extension that logs the call to commit
$ cat > $TESTTMP/logcommit.py << EOF
> from mercurial import extensions, localrepo
> def cb(sample):
> return len(sample)
> def _commit(orig, repo, *args, **kwargs):
> repo.ui.log("commit", "match filter", k=1, a={"hi":"ho"})
> repo.ui.log("foo", "does not match filter", k=1, a={"hi":"ho"})
> return orig(repo, *args, **kwargs)
> def extsetup(ui):
> extensions.wrapfunction(localrepo.localrepository, 'commit', _commit)
> EOF
Set up the extension and set a log file
We whitelist only the 'commit' key, only the events with that key will be
logged
$ cat >> $HGRCPATH << EOF
> [sampling]
> key.commit=commit_table
> [extensions]
> sampling=
> EOF
$ LOGDIR=`pwd`/logs
$ mkdir $LOGDIR
$ echo "logcommit=$TESTTMP/logcommit.py" >> $HGRCPATH
$ echo "[sampling]" >> $HGRCPATH
$ echo "filepath = $LOGDIR/samplingpath.txt" >> $HGRCPATH
Do a couple of commits we expect to log two call to repo.revs for each commit
$ mkcommit b
$ mkcommit c
>>> import json
>>> with open("$LOGDIR/samplingpath.txt") as f:
... data = f.read()
>>> for record in data.strip("\0").split("\0"):
... parsedrecord = json.loads(record)
... print parsedrecord["data"]["msg"], parsedrecord["category"]
... assert len(parsedrecord["data"]) == 4
[u'match filter'] commit_table
[u'match filter'] commit_table