sapling/tests/integration/test-lookup.t
Thomas Orozco 196a363236 mononoke: rebuild test framework
Summary:
Our test framework as it stands right now is a light passthrough to the hg `run-tests.py` test framework, which attempts to place all the files it needs to run (including tests) into a `python_binary`, then runs the hg test runner from that directory.

It heavily relies on how Buck works to offer functionality:

- It expects that all the sources it registers for its master binary will all be in the same directory when it builds
- It expects that the sources will be symlinks to the real files so that `--interactive` can work.

This has a few problems:

- It doesn't work in `mode/opt`. The archive that gets built in `mode/opt` doesn't actually have all the sources we registered, so it's impossible to run tests.
- To add a new test, you must rebuild everything. We don't do that very often, but it'd be nice if we didn't have to.
- Iterating on the runner itself is painful, because as far as Buck is concerned, it depends on the entire world. This means that every change to the runner has to scan a lot more stuff than necessary. There's some functionality I'd like to get into the runner (like reporting test timings) that hasn't been easy to add as a result.

This diff attempts to solve these problems by separating concerns a little more:

- The runner is now just a simple `python_binary`, so it's easier to make changes to it.
- The runner now provides the logic of working from local files when needed (this means you can add a new test and it'll work immediately),
- All the binaries we need are dependencies of the integration test target, not the runner's. However, to make it possible to run the runner incrementally while iterating on something, there's a manifest target that points at all the various paths the runner needs to work. This will also help integrate the test runner with other build frameworks if necessary (e.g. for open-sourcing).
- We have separate targets for various assets we need to run the tests (e.g. the hg test framework).
- The runner now controls whether to use the network blackhole. This was necessary because the network blackhole breaks PAR archives (because tmp is no longer owned by the right owner, because we use a user namespace). We should be able to bring this back at some point if we want to by using a proper chroot for opt tests.

I included a README to explain this new design as well.

There are some things that could yet stand to be improved here (notably, I think we should put assets and tests in different directories for the sake of clarity), but so far I've been aiming at providing a 1-1 translation of the old system into the new one. I am planning to make further improvements in followup diffs.

Reviewed By: farnz

Differential Revision: D15921732

fbshipit-source-id: 09052591c419acf97f7e360b1e88ef1f412da6e5
2019-06-25 08:41:31 -07:00

83 lines
2.4 KiB
Perl

$ . "${TEST_FIXTURES}/library.sh"
setup configuration
$ setup_mononoke_config
setup repo
$ cd $TESTTMP
$ hginit_treemanifest repo-hg
$ cd repo-hg
$ touch a
$ hg add a
$ hg ci -ma
$ touch b
$ hg add b
$ hg ci -ma
$ hg log
changeset: 1:f9ae6ef0865e
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: a
(re)
changeset: 0:3903775176ed
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: a
(re)
setup master bookmark
$ hg bookmark master_bookmark -r 3903775176ed
$ hg bookmark ffff775176ed42b1458a6281db4a0ccf4d9f287a
$ hg bookmark 3e19bf519e9af6c66edf28380101a92122cbea50
blobimport
$ cd $TESTTMP
$ blobimport repo-hg/.hg repo
start mononoke
$ mononoke
$ wait_for_mononoke $TESTTMP/repo
$ cd repo-hg
$ hg up -q 0
Helper script to test the lookup function
$ cat >> $TESTTMP/lookup.py <<EOF
> from edenscm.mercurial import registrar
> from edenscm.mercurial.node import bin
> from edenscm.mercurial import (bundle2, extensions)
> cmdtable = {}
> command = registrar.command(cmdtable)
> @command('lookup', [], ('key'))
> def _lookup(ui, repo, key, **opts):
> treemanifestext = extensions.find('treemanifest')
> fallbackpath = treemanifestext.getfallbackpath(repo)
> with repo.connectionpool.get(fallbackpath) as conn:
> remote = conn.peer
> csid = remote.lookup(key)
> if b'not found' in csid:
> print(csid)
> EOF
Lookup non-existent hash
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup fffffffffffff6c66edf28380101a92122cbea50
abort: fffffffffffff6c66edf28380101a92122cbea50 not found!
[255]
Lookup existing hash
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup f9ae6ef0865e00431f2af076be6b680f75dd2777
Lookup non-existent bookmark
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup fake_bookmark
abort: fake_bookmark not found!
[255]
Lookup existing bookmark
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup master_bookmark
Lookup bookmark with hash name that exists as a hash (returns hash)
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup 3903775176ed42b1458a6281db4a0ccf4d9f287a
Lookup bookmark with hash name that doesn't exist as a hash (returns bookmark -> hash)
$ hgmn --config extensions.lookup=$TESTTMP/lookup.py lookup ffff775176ed42b1458a6281db4a0ccf4d9f287a