| 1 |
#require no-windows no-rhg |
| 2 |
|
| 3 |
XXX-RHG this test hangs if `hg` is really `rhg`. This was hidden by the use of |
| 4 |
`alias hg=rhg` by run-tests.py. With such alias removed, this test is revealed |
| 5 |
buggy. This need to be resolved sooner than later. |
| 6 |
|
| 7 |
Dummy extension simulating unsafe long running command |
| 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 |
| 15 |
> import time |
| 16 |
> |
| 17 |
> from mercurial.i18n import _ |
| 18 |
> from mercurial import registrar |
| 19 |
> from mercurial import testing |
| 20 |
> |
| 21 |
> cmdtable = {} |
| 22 |
> command = registrar.command(cmdtable) |
| 23 |
> |
| 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() |
| 27 |
> with ui.uninterruptible(): |
| 28 |
> testing.write_file(sync_file, b'%d' % os.getpid()) |
| 29 |
> testing.wait_file(done_file) |
| 30 |
> ui.warn(b"end of unsafe operation\n") |
| 31 |
> ui.warn(b"%d second(s) passed\n" % int(time.time() - start)) |
| 32 |
> EOF |
| 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 |
> EOF |
| 44 |
|
| 45 |
#if no-windows |
| 46 |
$ chmod +x send-signal.sh |
| 47 |
#endif |
| 48 |
|
| 49 |
$ cat > wait-signal.sh << 'EOF' |
| 50 |
> #!/bin/sh |
| 51 |
> (hg wait-signal 2>&1; echo [$?]) | { |
| 52 |
> read line |
| 53 |
> touch "$DONE_FILE" |
| 54 |
> echo "$line" |
| 55 |
> cat |
| 56 |
> } |
| 57 |
> EOF |
| 58 |
|
| 59 |
#if no-windows |
| 60 |
$ chmod +x wait-signal.sh |
| 61 |
#endif |
| 62 |
|
| 63 |
Kludge to emulate timeout(1) which is not generally available. |
| 64 |
|
| 65 |
Set up repository |
| 66 |
$ hg init repo |
| 67 |
$ cd repo |
| 68 |
$ cat >> $HGRCPATH << EOF |
| 69 |
> [extensions] |
| 70 |
> wait_ext = $TESTTMP/wait_ext.py |
| 71 |
> EOF |
| 72 |
|
| 73 |
Test ctrl-c |
| 74 |
$ rm -f $SYNC_FILE $DONE_FILE |
| 75 |
$ sh -c "../send-signal.sh INT" & |
| 76 |
$ ../wait-signal.sh |
| 77 |
interrupted! |
| 78 |
[255] |
| 79 |
|
| 80 |
$ cat >> $HGRCPATH << EOF |
| 81 |
> [experimental] |
| 82 |
> nointerrupt = yes |
| 83 |
> EOF |
| 84 |
|
| 85 |
$ rm -f $SYNC_FILE $DONE_FILE |
| 86 |
$ sh -c "../send-signal.sh INT" & |
| 87 |
$ ../wait-signal.sh |
| 88 |
interrupted! |
| 89 |
[255] |
| 90 |
|
| 91 |
$ cat >> $HGRCPATH << EOF |
| 92 |
> [experimental] |
| 93 |
> nointerrupt-interactiveonly = False |
| 94 |
> EOF |
| 95 |
|
| 96 |
$ rm -f $SYNC_FILE $DONE_FILE |
| 97 |
$ sh -c "../send-signal.sh INT" & |
| 98 |
$ ../wait-signal.sh |
| 99 |
shutting down cleanly |
| 100 |
press ^C again to terminate immediately (dangerous) |
| 101 |
end of unsafe operation |
| 102 |
interrupted! |
| 103 |
[255] |