Gregory Szorc <gregory.szorc@gmail.com> [Tue, 18 Sep 2018 16:52:11 -0700] rev 39772
testing: add interface unit tests for file storage
Our strategy for supporting alternate storage backends is to define
interfaces for everything then "code to the interface."
We already have interfaces for various primitives, including file
and manifest storage.
What we don't have is generic unit tests for those interfaces. Up
to this point we've been relying on high-level integration tests
(mainly in the form of existing .t tests) to test alternate storage
backends. And my experience with developing the "simple store" test
extension is that such testing is very tedious: it takes several
minutes to run all tests and when you find a failure, it is often
non-trivial to debug.
This commit starts to change that.
This commit introduces the mercurial.testing.storage module. It
contains testing code for storage. Currently, it defines some
unittest.TestCase classes for testing the file storage interfaces.
It also defines some factory functions that allow a caller to easily
spawn a custom TestCase "bound" to a specific file storage backend
implementation.
A new .py test has been added. It simply defines a callable to produce
filelog and transaction instances on demand and then "registers" the
various test classes so the filelog class can be tested with the
storage interface unit tests.
As part of writing the tests, I identified a couple of apparent
bugs in revlog.py and filelog.py! These are tracked with inline
TODO comments.
Writing the tests makes it more obvious where the storage interface
is lacking. For example, we raise either IndexError or
error.LookupError for missing revisions depending on whether we
use an integer revision or a node. Also, we raise error.RevlogError
in various places when we should be raising a storage-agnostic
error type.
The storage interfaces are currently far from perfect and there is much
work to be done to improve them. But at least with this commit we
finally have the start of unit tests that can be used to "qualify"
the behavior of a storage backend. And when implementing and debugging
new storage backends, we now have an obvious place to define new
tests and have obvious places to insert breakpoints to facilitate
debugging. This should be invaluable when implementing new storage
backends.
I added the mercurial.testing package because these interface
conformance tests are generic and need to be usable by all storage
backends. Having the code live in tests/ would make it difficult for
storage backends implemented in extensions to test their interface
conformance. First, it would require obtaining a copy of Mercurial's
storage test code in order to test. Second, it would make testing
against multiple Mercurial versions difficult, as you would need to
import N copies of the storage testing code in order to achieve test
coverage. By making the test code part of the Mercurial distribution
itself, extensions can `import mercurial.testing.*` to access and run
the test code. The test will run against whatever Mercurial version
is active.
FWIW I've always wanted to move parts of run-tests.py into the
mercurial.* package to make the testing story simpler (e.g. imagine an
`hg debugruntests` command that could invoke the test harness). While I
have no plans to do that in the near future, establishing the
mercurial.testing package does provide a natural home for that code
should someone do this in the future.
Differential Revision: https://phab.mercurial-scm.org/D4650
Gregory Szorc <gregory.szorc@gmail.com> [Tue, 18 Sep 2018 15:32:11 -0700] rev 39771
narrow: remove narrowrevlog
Core now automatically enables ellipsis support on revlogs when
repositories have narrow enabled. So, we no longer need to globally
register the revlog flag as part of activating the narrow extension
and this code can be deleted.
A side effect of this change is that repositories will now raise an
error on encountering an ellipsis flag when the narrow extension is
loaded. Previously, loading the narrow extension on a non-narrow repo
could result in silent usage of the ellipsis flag. This could lead
to undetected bugs. I think the new behavior is more correct.
Differential Revision: https://phab.mercurial-scm.org/D4649
Gregory Szorc <gregory.szorc@gmail.com> [Thu, 13 Sep 2018 15:57:18 -0700] rev 39770
localrepo: enable ellipsis flag on revlogs when repo is narrow
If the narrow requirement is present, revlogs created for that
repository will have the ellipsis flag enabled.
This is the same behavior that the narrow extension exhibits. Except
the ellipsis flag won't be enabled on repos/revlogs that don't have
the narrow requirement.
Differential Revision: https://phab.mercurial-scm.org/D4648
Gregory Szorc <gregory.szorc@gmail.com> [Thu, 13 Sep 2018 15:52:42 -0700] rev 39769
revlog: add opener option to enable ellipsis flag processor
The ellipsis flag processor can now be registered by specifying
an opener option when constructing a revlog instance. This allows
us to enable ellipsis flags on a per-revlog basis.
Differential Revision: https://phab.mercurial-scm.org/D4647
Gregory Szorc <gregory.szorc@gmail.com> [Thu, 13 Sep 2018 15:48:53 -0700] rev 39768
revlog: store flag processors per revlog
Previously, revlog flag processing would consult a global dict
when processing flags. This was simple. But it had the undesired
side-effect that any extension could load flag processors once
and those flag processors would be available to any revlog that was
subsequent loaded in the process. e.g. in hgweb, if the narrow
extension were loaded for repo A but not repo B, repo B would be
able to decode ellipsis flags even though it shouldn't be able to.
Making the flag processors dict per-revlog allows us to have per-revlog
controls over what flag processors are available, thus preserving
desired granular access to flag processors depending on the revlog's
needs.
If a flag processor is globally registered, it is still globally
available. So this commit should not meaningfully change behavior.
Differential Revision: https://phab.mercurial-scm.org/D4646
Gregory Szorc <gregory.szorc@gmail.com> [Wed, 05 Sep 2018 13:29:22 -0700] rev 39767
revlog: define ellipsis flag processors in core
We will soon be teaching core to honor the ellipsis flag on revlogs.
Moving the definition of the processor functions to core is the first
step in this.
The processor is still not registered unless the narrow extension is
loaded.
Differential Revision: https://phab.mercurial-scm.org/D4645
Gregory Szorc <gregory.szorc@gmail.com> [Wed, 05 Sep 2018 12:44:25 -0700] rev 39766
narrow: remove custom filelog type
This functionality is now handled by core as of the previous commit.
I wanted this to be a standalone commit because the deleted code
makes a reference to remotefilelog's file type missing a node() method
and this may have implications to narrow+remotefilelog usage. The code
in core doesn't perform this check and therefore behavior may be subtly
different and buggy.
But I /think/ the check is merely a performance optimization and
nothing more. So I'm optimistic this will continue to "just work."
Differential Revision: https://phab.mercurial-scm.org/D4644
Gregory Szorc <gregory.szorc@gmail.com> [Thu, 13 Sep 2018 16:02:22 -0700] rev 39765
filelog: custom filelog to be used with narrow repos
Narrow repos may have file revisions whose copy/rename metadata
references files not in the store. This can pose problems when
consumers attempt to access a missing referenced file revision.
The narrow extension hacks around this problem by implementing a
derived filelog type that provides custom implementations of
renamed(), size(), and cmp() which handle renames against files not
in the narrow spec by silently removing the rename metadata.
While silently dropping metadata isn't the most robust solution,
it is the easiest to implement.
This commit ports the custom narrow filelog class to core.
When a narrow repo is constructed, its ifilestorage creation
function will automatically use the new filelog type. This means
the extra logic is 0 cost for non-narrow repos and shouldn't
interfere with their operation.
Differential Revision: https://phab.mercurial-scm.org/D4643