Show More
@@ -5,85 +5,87 XXX-RHG this test hangs if `hg` is reall | |||
|
5 | 5 | buggy. This need to be resolved sooner than later. |
|
6 | 6 | |
|
7 | 7 | Dummy extension simulating unsafe long running command |
|
8 | $ cat > sleepext.py <<EOF | |
|
9 | > import itertools | |
|
8 | $ SYNC_FILE="$TESTTMP/sync-file" | |
|
9 | $ export SYNC_FILE | |
|
10 | $ DONE_FILE="$TESTTMP/done-file" | |
|
11 | $ export DONE_FILE | |
|
12 | $ | |
|
13 | $ cat > wait_ext.py <<EOF | |
|
14 | > import os | |
|
10 | 15 | > import time |
|
11 | 16 | > |
|
12 | 17 | > from mercurial.i18n import _ |
|
13 | 18 | > from mercurial import registrar |
|
19 | > from mercurial import testing | |
|
14 | 20 | > |
|
15 | 21 | > cmdtable = {} |
|
16 | 22 | > command = registrar.command(cmdtable) |
|
17 | 23 | > |
|
18 |
> @command(b'sl |
|
|
19 | > def sleep(ui, sleeptime=b"1", **opts): | |
|
24 | > @command(b'wait-signal', [], _(b'SYNC_FILE DONE_FILE'), norepo=True) | |
|
25 | > def sleep(ui, sync_file=b"$SYNC_FILE", done_file=b"$DONE_FILE", **opts): | |
|
26 | > start = time.time() | |
|
20 | 27 | > with ui.uninterruptible(): |
|
21 | > for _i in itertools.repeat(None, int(sleeptime)): | |
|
22 | > time.sleep(1) | |
|
28 | > testing.write_file(sync_file, b'%d' % os.getpid()) | |
|
29 | > testing.wait_file(done_file) | |
|
23 | 30 | > ui.warn(b"end of unsafe operation\n") |
|
24 |
> ui.warn(b"% |
|
|
31 | > ui.warn(b"%d second(s) passed\n" % int(time.time() - start)) | |
|
25 | 32 | > EOF |
|
26 | 33 | |
|
34 | $ cat > send-signal.sh << EOF | |
|
35 | > #!/bin/sh | |
|
36 | > SIG=\$1 | |
|
37 | > if [ -z "\$SIG" ]; then | |
|
38 | > echo "send-signal.sh requires one argument" >&2 | |
|
39 | > exit 1 | |
|
40 | > fi | |
|
41 | > "$RUNTESTDIR/testlib/wait-on-file" 10 "$SYNC_FILE" || exit 2 | |
|
42 | > kill -s \$SIG \`cat "$SYNC_FILE"\` | |
|
43 | > touch "$DONE_FILE" | |
|
44 | > EOF | |
|
45 | ||
|
46 | #if no-windows | |
|
47 | $ chmod +x send-signal.sh | |
|
48 | #endif | |
|
49 | ||
|
27 | 50 | Kludge to emulate timeout(1) which is not generally available. |
|
28 | $ cat > timeout.py <<EOF | |
|
29 | > from __future__ import print_function | |
|
30 | > import argparse | |
|
31 | > import signal | |
|
32 | > import subprocess | |
|
33 | > import sys | |
|
34 | > import time | |
|
35 | > | |
|
36 | > ap = argparse.ArgumentParser() | |
|
37 | > ap.add_argument('-s', nargs=1, default='SIGTERM') | |
|
38 | > ap.add_argument('duration', nargs=1, type=int) | |
|
39 | > ap.add_argument('argv', nargs='*') | |
|
40 | > opts = ap.parse_args() | |
|
41 | > try: | |
|
42 | > sig = int(opts.s[0]) | |
|
43 | > except ValueError: | |
|
44 | > sname = opts.s[0] | |
|
45 | > if not sname.startswith('SIG'): | |
|
46 | > sname = 'SIG' + sname | |
|
47 | > sig = getattr(signal, sname) | |
|
48 | > proc = subprocess.Popen(opts.argv) | |
|
49 | > time.sleep(opts.duration[0]) | |
|
50 | > proc.poll() | |
|
51 | > if proc.returncode is None: | |
|
52 | > proc.send_signal(sig) | |
|
53 | > proc.wait() | |
|
54 | > sys.exit(124) | |
|
55 | > EOF | |
|
56 | 51 | |
|
57 | 52 | Set up repository |
|
58 | 53 | $ hg init repo |
|
59 | 54 | $ cd repo |
|
60 | 55 | $ cat >> $HGRCPATH << EOF |
|
61 | 56 | > [extensions] |
|
62 | > sleepext = ../sleepext.py | |
|
57 | > wait_ext = $TESTTMP/wait_ext.py | |
|
63 | 58 | > EOF |
|
64 | 59 | |
|
60 | ||
|
65 | 61 | Test ctrl-c |
|
66 | $ "$PYTHON" $TESTTMP/timeout.py -s INT 1 hg sleep 2 | |
|
62 | $ rm -f $SYNC_FILE $DONE_FILE | |
|
63 | $ sh -c "../send-signal.sh INT" & | |
|
64 | $ hg wait-signal | |
|
67 | 65 | interrupted! |
|
68 |
[ |
|
|
66 | [255] | |
|
69 | 67 | |
|
70 | 68 | $ cat >> $HGRCPATH << EOF |
|
71 | 69 | > [experimental] |
|
72 | 70 | > nointerrupt = yes |
|
73 | 71 | > EOF |
|
74 | 72 | |
|
75 | $ "$PYTHON" $TESTTMP/timeout.py -s INT 1 hg sleep 2 | |
|
73 | $ rm -f $SYNC_FILE $DONE_FILE | |
|
74 | $ sh -c "../send-signal.sh INT" & | |
|
75 | $ hg wait-signal | |
|
76 | 76 | interrupted! |
|
77 |
[ |
|
|
77 | [255] | |
|
78 | 78 | |
|
79 | 79 | $ cat >> $HGRCPATH << EOF |
|
80 | 80 | > [experimental] |
|
81 | 81 | > nointerrupt-interactiveonly = False |
|
82 | 82 | > EOF |
|
83 | 83 | |
|
84 | $ "$PYTHON" $TESTTMP/timeout.py -s INT 1 hg sleep 2 | |
|
84 | $ rm -f $SYNC_FILE $DONE_FILE | |
|
85 | $ sh -c "../send-signal.sh INT" & | |
|
86 | $ hg wait-signal | |
|
85 | 87 | shutting down cleanly |
|
86 | 88 | press ^C again to terminate immediately (dangerous) |
|
87 | 89 | end of unsafe operation |
|
88 | 90 | interrupted! |
|
89 |
[ |
|
|
91 | [255] |
General Comments 0
You need to be logged in to leave comments.
Login now