##// END OF EJS Templates
test: remove `sleep` usage in `test-nointerrupt.t` (issue6271)...
marmoute -
r48562:f48a688a stable
parent child Browse files
Show More
@@ -5,85 +5,87 b' XXX-RHG this test hangs if `hg` is reall'
5 buggy. This need to be resolved sooner than later.
5 buggy. This need to be resolved sooner than later.
6
6
7 Dummy extension simulating unsafe long running command
7 Dummy extension simulating unsafe long running command
8 $ cat > sleepext.py <<EOF
8 $ SYNC_FILE="$TESTTMP/sync-file"
9 > import itertools
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 > import time
15 > import time
11 >
16 >
12 > from mercurial.i18n import _
17 > from mercurial.i18n import _
13 > from mercurial import registrar
18 > from mercurial import registrar
19 > from mercurial import testing
14 >
20 >
15 > cmdtable = {}
21 > cmdtable = {}
16 > command = registrar.command(cmdtable)
22 > command = registrar.command(cmdtable)
17 >
23 >
18 > @command(b'sleep', [], _(b'TIME'), norepo=True)
24 > @command(b'wait-signal', [], _(b'SYNC_FILE DONE_FILE'), norepo=True)
19 > def sleep(ui, sleeptime=b"1", **opts):
25 > def sleep(ui, sync_file=b"$SYNC_FILE", done_file=b"$DONE_FILE", **opts):
26 > start = time.time()
20 > with ui.uninterruptible():
27 > with ui.uninterruptible():
21 > for _i in itertools.repeat(None, int(sleeptime)):
28 > testing.write_file(sync_file, b'%d' % os.getpid())
22 > time.sleep(1)
29 > testing.wait_file(done_file)
23 > ui.warn(b"end of unsafe operation\n")
30 > ui.warn(b"end of unsafe operation\n")
24 > ui.warn(b"%s second(s) passed\n" % sleeptime)
31 > ui.warn(b"%d second(s) passed\n" % int(time.time() - start))
25 > EOF
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 Kludge to emulate timeout(1) which is not generally available.
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 Set up repository
52 Set up repository
58 $ hg init repo
53 $ hg init repo
59 $ cd repo
54 $ cd repo
60 $ cat >> $HGRCPATH << EOF
55 $ cat >> $HGRCPATH << EOF
61 > [extensions]
56 > [extensions]
62 > sleepext = ../sleepext.py
57 > wait_ext = $TESTTMP/wait_ext.py
63 > EOF
58 > EOF
64
59
60
65 Test ctrl-c
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 interrupted!
65 interrupted!
68 [124]
66 [255]
69
67
70 $ cat >> $HGRCPATH << EOF
68 $ cat >> $HGRCPATH << EOF
71 > [experimental]
69 > [experimental]
72 > nointerrupt = yes
70 > nointerrupt = yes
73 > EOF
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 interrupted!
76 interrupted!
77 [124]
77 [255]
78
78
79 $ cat >> $HGRCPATH << EOF
79 $ cat >> $HGRCPATH << EOF
80 > [experimental]
80 > [experimental]
81 > nointerrupt-interactiveonly = False
81 > nointerrupt-interactiveonly = False
82 > EOF
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 shutting down cleanly
87 shutting down cleanly
86 press ^C again to terminate immediately (dangerous)
88 press ^C again to terminate immediately (dangerous)
87 end of unsafe operation
89 end of unsafe operation
88 interrupted!
90 interrupted!
89 [124]
91 [255]
General Comments 0
You need to be logged in to leave comments. Login now