sapling/tests/test-rebase-inmemory-mergedriver.t
Phil Cohen 73acd830dd mergedriver: fix the invalidation flakiness by setting sys.dont_write_bytecode
Summary:
D8464848 added code to invalidate merge drivers after running them, for reasons described in that diff.

But it turns out deleting from sys.modules is not enough, because Python will occasionally write a `.pyc` of the original hook, and re-use it when loading again, thus bypassing the invalidation.

This doesn't happen at all on my Mac, but happens approximately every other time when running on CentOS. Thanks to DurhamG who discovered the flakiness.

This fixes the flakiness of the test, and AFAIK this would be a problem in the wild, too, though we haven't heard of it yet.

Reviewed By: singhsrb

Differential Revision: D8675720

fbshipit-source-id: bec8fec6af9a362db1f0dd5d262932cbda6137ff
2018-06-29 10:47:38 -07:00

101 lines
3.4 KiB
Perl

Test mergedriver invalidation with IMM.
$ newrepo
$ enable rebase
$ setconfig rebase.singletransaction=True
$ setconfig rebase.experimental.inmemory=True
$ setconfig rebase.experimental.inmemory.nomergedriver=False
$ setconfig rebase.experimental.inmemorywarning="rebasing in-memory!"
$ mkdir driver
$ cat >> driver/__init__.py <<EOF
> from .generators import someFunction, VERSION
> def preprocess(ui, repo, hooktype, mergestate, wctx, labels=None):
> unresolved_files = list(mergestate.unresolved())
> ui.warn("generators version = %s\n" % VERSION)
> someFunction(repo)
> for unresolved_file in unresolved_files:
> mergestate.mark(unresolved_file, 'd')
> mergestate.commit()
> def conclude(ui, repo, hooktype, mergestate, wctx, labels=None):
> pass
> EOF
$ cat > driver/generators.py <<EOF
> VERSION = "BASE"
> def someFunction(repo):
> repo.ui.warn("base's someFunction() called\n")
> pass
> EOF
$ setconfig experimental.mergedriver=python:driver/
A dummy file (FILE) is created to force a simple three-way merge (without
conflicts, though a conflict would work too). Otherwise, mergedriver won't run.
$ $TESTDIR/seq.py 1 10 > FILE
$ hg add FILE
$ hg commit -Aq -m "base mergedriver"
$ hg book -r . "base"
Next, off of BASE, make an API change to the driver.
$ cat > driver/__init__.py <<EOF
> from .generators import someFunction, VERSION
>
> def preprocess(ui, repo, hooktype, mergestate, wctx, labels=None):
> unresolved_files = list(mergestate.unresolved())
> ui.warn("generators version = %s\n" % VERSION)
> someFunction(repo, "new_required")
>
> for unresolved_file in unresolved_files:
> mergestate.mark(unresolved_file, 'd')
>
> mergestate.commit()
>
> def conclude(ui, repo, hooktype, mergestate, wctx, labels=None):
> pass
> EOF
$ cat > driver/generators.py <<EOF
> VERSION = "NEW"
>
> def someFunction(repo, new_required_arg):
> print("new_required_arg = %s" % new_required_arg)
> pass
> EOF
$ $TESTDIR/seq.py 1 11 > FILE
$ hg com -m "new driver"
$ hg book -r . new_driver
$ hg up -q .~1
Next make a change to the dummy file off BASE.
$ hg up base
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
(activating bookmark base)
$ hg up -C .
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
(leaving bookmark base)
$ $TESTDIR/seq.py 0 10 > FILE
$ hg commit -m "prefix FILE with 0"
$ hg book -r . "base_1"
Rebase on top of the new driver, with the old driver checked out.
- We expect to see "generators version = BASE" as we run preprocess() with the old driver.
- Then, after restarting and using on-disk merge (and thus, checking out dest, which has the new driver),
we expect to see "generators version = NEW".
- If mergedriver isn't invalidated correctly, it'll say "generators version = BASE".
$ hg rebase -d new_driver
rebasing in-memory!
rebasing 2:* "prefix FILE with 0" (base_1 tip) (glob)
generators version = BASE
base's someFunction() called
hit merge conflicts; using on-disk merge instead (some of your files require mergedriver to run, which in-memory merge does not support)
rebasing 2:* "prefix FILE with 0" (base_1 tip) (glob)
generators version = NEW
new_required_arg = new_required
note: rebase of 2:* created no changes to commit (glob)
saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/*-rebase.hg (glob)