Show More
@@ -1,83 +1,85 b'' | |||||
|
1 | #require no-windows | |||
|
2 | ||||
1 | Dummy extension simulating unsafe long running command |
|
3 | Dummy extension simulating unsafe long running command | |
2 | $ cat > sleepext.py <<EOF |
|
4 | $ cat > sleepext.py <<EOF | |
3 | > import itertools |
|
5 | > import itertools | |
4 | > import time |
|
6 | > import time | |
5 | > |
|
7 | > | |
6 | > from mercurial.i18n import _ |
|
8 | > from mercurial.i18n import _ | |
7 | > from mercurial import registrar |
|
9 | > from mercurial import registrar | |
8 | > |
|
10 | > | |
9 | > cmdtable = {} |
|
11 | > cmdtable = {} | |
10 | > command = registrar.command(cmdtable) |
|
12 | > command = registrar.command(cmdtable) | |
11 | > |
|
13 | > | |
12 | > @command(b'sleep', [], _(b'TIME'), norepo=True) |
|
14 | > @command(b'sleep', [], _(b'TIME'), norepo=True) | |
13 | > def sleep(ui, sleeptime=b"1", **opts): |
|
15 | > def sleep(ui, sleeptime=b"1", **opts): | |
14 | > with ui.uninterruptable(): |
|
16 | > with ui.uninterruptable(): | |
15 | > for _i in itertools.repeat(None, int(sleeptime)): |
|
17 | > for _i in itertools.repeat(None, int(sleeptime)): | |
16 | > time.sleep(1) |
|
18 | > time.sleep(1) | |
17 | > ui.warn(b"end of unsafe operation\n") |
|
19 | > ui.warn(b"end of unsafe operation\n") | |
18 | > ui.warn(b"%s second(s) passed\n" % sleeptime) |
|
20 | > ui.warn(b"%s second(s) passed\n" % sleeptime) | |
19 | > EOF |
|
21 | > EOF | |
20 |
|
22 | |||
21 | Kludge to emulate timeout(1) which is not generally available. |
|
23 | Kludge to emulate timeout(1) which is not generally available. | |
22 | $ cat > timeout.py <<EOF |
|
24 | $ cat > timeout.py <<EOF | |
23 | > from __future__ import print_function |
|
25 | > from __future__ import print_function | |
24 | > import argparse |
|
26 | > import argparse | |
25 | > import signal |
|
27 | > import signal | |
26 | > import subprocess |
|
28 | > import subprocess | |
27 | > import sys |
|
29 | > import sys | |
28 | > import time |
|
30 | > import time | |
29 | > |
|
31 | > | |
30 | > ap = argparse.ArgumentParser() |
|
32 | > ap = argparse.ArgumentParser() | |
31 | > ap.add_argument('-s', nargs=1, default='SIGTERM') |
|
33 | > ap.add_argument('-s', nargs=1, default='SIGTERM') | |
32 | > ap.add_argument('duration', nargs=1, type=int) |
|
34 | > ap.add_argument('duration', nargs=1, type=int) | |
33 | > ap.add_argument('argv', nargs='*') |
|
35 | > ap.add_argument('argv', nargs='*') | |
34 | > opts = ap.parse_args() |
|
36 | > opts = ap.parse_args() | |
35 | > try: |
|
37 | > try: | |
36 | > sig = int(opts.s[0]) |
|
38 | > sig = int(opts.s[0]) | |
37 | > except ValueError: |
|
39 | > except ValueError: | |
38 | > sname = opts.s[0] |
|
40 | > sname = opts.s[0] | |
39 | > if not sname.startswith('SIG'): |
|
41 | > if not sname.startswith('SIG'): | |
40 | > sname = 'SIG' + sname |
|
42 | > sname = 'SIG' + sname | |
41 | > sig = getattr(signal, sname) |
|
43 | > sig = getattr(signal, sname) | |
42 | > proc = subprocess.Popen(opts.argv) |
|
44 | > proc = subprocess.Popen(opts.argv) | |
43 | > time.sleep(opts.duration[0]) |
|
45 | > time.sleep(opts.duration[0]) | |
44 | > proc.poll() |
|
46 | > proc.poll() | |
45 | > if proc.returncode is None: |
|
47 | > if proc.returncode is None: | |
46 | > proc.send_signal(sig) |
|
48 | > proc.send_signal(sig) | |
47 | > proc.wait() |
|
49 | > proc.wait() | |
48 | > sys.exit(124) |
|
50 | > sys.exit(124) | |
49 | > EOF |
|
51 | > EOF | |
50 |
|
52 | |||
51 | Set up repository |
|
53 | Set up repository | |
52 | $ hg init repo |
|
54 | $ hg init repo | |
53 | $ cd repo |
|
55 | $ cd repo | |
54 | $ cat >> $HGRCPATH << EOF |
|
56 | $ cat >> $HGRCPATH << EOF | |
55 | > [extensions] |
|
57 | > [extensions] | |
56 | > sleepext = ../sleepext.py |
|
58 | > sleepext = ../sleepext.py | |
57 | > EOF |
|
59 | > EOF | |
58 |
|
60 | |||
59 | Test ctrl-c |
|
61 | Test ctrl-c | |
60 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 |
|
62 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 | |
61 | interrupted! |
|
63 | interrupted! | |
62 | [124] |
|
64 | [124] | |
63 |
|
65 | |||
64 | $ cat >> $HGRCPATH << EOF |
|
66 | $ cat >> $HGRCPATH << EOF | |
65 | > [experimental] |
|
67 | > [experimental] | |
66 | > nointerrupt = yes |
|
68 | > nointerrupt = yes | |
67 | > EOF |
|
69 | > EOF | |
68 |
|
70 | |||
69 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 |
|
71 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 | |
70 | interrupted! |
|
72 | interrupted! | |
71 | [124] |
|
73 | [124] | |
72 |
|
74 | |||
73 | $ cat >> $HGRCPATH << EOF |
|
75 | $ cat >> $HGRCPATH << EOF | |
74 | > [experimental] |
|
76 | > [experimental] | |
75 | > nointerrupt-interactiveonly = False |
|
77 | > nointerrupt-interactiveonly = False | |
76 | > EOF |
|
78 | > EOF | |
77 |
|
79 | |||
78 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 |
|
80 | $ python $TESTTMP/timeout.py -s INT 1 hg sleep 2 | |
79 | shutting down cleanly |
|
81 | shutting down cleanly | |
80 | press ^C again to terminate immediately (dangerous) |
|
82 | press ^C again to terminate immediately (dangerous) | |
81 | end of unsafe operation |
|
83 | end of unsafe operation | |
82 | interrupted! |
|
84 | interrupted! | |
83 | [124] |
|
85 | [124] |
General Comments 0
You need to be logged in to leave comments.
Login now