sapling/tests/test-fb-hgext-nointerrupt.t
Jun Wu 9dc21f8d0b codemod: import from the edenscm package
Summary:
D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`.
That has nasty problems if both `import mercurial` and
`import edenscm.mercurial` are used, because Python would think `mercurial.foo`
and `edenscm.mercurial.foo` are different modules so code like
`try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)`
would fail to handle the `edenscm.mercurial` version. There are also some
module-level states (ex. `extensions._extensions`) that would cause trouble if
they have multiple versions in a single process.

Change imports to use the `edenscm` so ideally the `mercurial` is no longer
imported at all. Add checks in extensions.py to catch unexpected extensions
importing modules from the old (wrong) locations when running tests.

Reviewed By: phillco

Differential Revision: D13868981

fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
2019-01-29 17:25:32 -08:00

81 lines
1.7 KiB
Perl

Dummy extension simulating long running command
$ cat > sleepext.py <<EOF
> import time
> import itertools
>
> from edenscm.mercurial import registrar
> from edenscm.mercurial.i18n import _
>
> cmdtable = {}
> command = registrar.command(cmdtable)
>
> @command('sleep', [], _('TIME'), norepo=True)
> def sleep(ui, sleeptime="1", **opts):
>
> for _i in itertools.repeat(None, int(sleeptime)):
> time.sleep(1)
>
> ui.warn("%s second(s) passed\n" % sleeptime)
> EOF
Set up repository
$ hg init repo
$ cd repo
$ cat >> $HGRCPATH << EOF
> [extensions]
> sleepext = ../sleepext.py
> EOF
#if osx
$ TIMEOUT=gtimeout
#else
$ TIMEOUT=timeout
#endif
$ hash $TIMEOUT 2>/dev/null
> HASHSTATUS=$?
> if [ $HASHSTATUS -ne 0 ] ; then
> echo "skipped: missing feature: $TIMEOUT"
> exit 80
> fi
Test ctrl-c
$ $TIMEOUT -s 2 1 hg sleep 2
interrupted!
[124]
$ cat >> $HGRCPATH << EOF
> nointerrupt=
> [alias]
> slumber = sleep
> [nointerrupt]
> attend-sleep = True
> attend-update = True
> EOF
$ $TIMEOUT -s 2 1 hg sleep 2
interrupted!
[124]
$ cat >> $HGRCPATH << EOF
> interactiveonly = False
> EOF
$ $TIMEOUT -s 2 1 hg sleep 2
==========================
Interrupting Mercurial may leave your repo in a bad state.
If you really want to interrupt your current command, press
CTRL-C again.
==========================
2 second(s) passed
[124]
$ $TIMEOUT -s 2 1 hg slum 2
==========================
Interrupting Mercurial may leave your repo in a bad state.
If you really want to interrupt your current command, press
CTRL-C again.
==========================
2 second(s) passed
[124]