tests/test-nointerrupt.t
branchstable
changeset 49446 8c75ae3f0eea
parent 48255 8c34edb1ad10
equal deleted inserted replaced
49436:e4e33b779fa2 49446:8c75ae3f0eea
    25   > def sleep(ui, sync_file=b"$SYNC_FILE", done_file=b"$DONE_FILE", **opts):
    25   > def sleep(ui, sync_file=b"$SYNC_FILE", done_file=b"$DONE_FILE", **opts):
    26   >     start = time.time()
    26   >     start = time.time()
    27   >     with ui.uninterruptible():
    27   >     with ui.uninterruptible():
    28   >         testing.write_file(sync_file, b'%d' % os.getpid())
    28   >         testing.write_file(sync_file, b'%d' % os.getpid())
    29   >         testing.wait_file(done_file)
    29   >         testing.wait_file(done_file)
    30   >         # make sure we get rescheduled and the signal get a chance to be handled
       
    31   >         time.sleep(0.1)
       
    32   >         ui.warn(b"end of unsafe operation\n")
    30   >         ui.warn(b"end of unsafe operation\n")
    33   >     ui.warn(b"%d second(s) passed\n" % int(time.time() - start))
    31   >     ui.warn(b"%d second(s) passed\n" % int(time.time() - start))
    34   > EOF
    32   > EOF
    35 
    33 
    36   $ cat > send-signal.sh << EOF
    34   $ cat > send-signal.sh << EOF
    40   >    echo "send-signal.sh requires one argument" >&2
    38   >    echo "send-signal.sh requires one argument" >&2
    41   >    exit 1
    39   >    exit 1
    42   > fi
    40   > fi
    43   > "$RUNTESTDIR/testlib/wait-on-file" 10 "$SYNC_FILE" || exit 2
    41   > "$RUNTESTDIR/testlib/wait-on-file" 10 "$SYNC_FILE" || exit 2
    44   > kill -s \$SIG \`cat "$SYNC_FILE"\`
    42   > kill -s \$SIG \`cat "$SYNC_FILE"\`
    45   > sleep 1
       
    46   > touch "$DONE_FILE"
       
    47   > EOF
    43   > EOF
    48 
    44 
    49 #if no-windows
    45 #if no-windows
    50   $ chmod +x send-signal.sh
    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
    51 #endif
    61 #endif
    52 
    62 
    53 Kludge to emulate timeout(1) which is not generally available.
    63 Kludge to emulate timeout(1) which is not generally available.
    54 
    64 
    55 Set up repository
    65 Set up repository
    58   $ cat >> $HGRCPATH << EOF
    68   $ cat >> $HGRCPATH << EOF
    59   > [extensions]
    69   > [extensions]
    60   > wait_ext = $TESTTMP/wait_ext.py
    70   > wait_ext = $TESTTMP/wait_ext.py
    61   > EOF
    71   > EOF
    62 
    72 
    63 
       
    64 Test ctrl-c
    73 Test ctrl-c
    65   $ rm -f $SYNC_FILE $DONE_FILE
    74   $ rm -f $SYNC_FILE $DONE_FILE
    66   $ sh -c "../send-signal.sh INT" &
    75   $ sh -c "../send-signal.sh INT" &
    67   $ hg wait-signal
    76   $ ../wait-signal.sh
    68   interrupted!
    77   interrupted!
    69   [255]
    78   [255]
    70 
    79 
    71   $ cat >> $HGRCPATH << EOF
    80   $ cat >> $HGRCPATH << EOF
    72   > [experimental]
    81   > [experimental]
    73   > nointerrupt = yes
    82   > nointerrupt = yes
    74   > EOF
    83   > EOF
    75 
    84 
    76   $ rm -f $SYNC_FILE $DONE_FILE
    85   $ rm -f $SYNC_FILE $DONE_FILE
    77   $ sh -c "../send-signal.sh INT" &
    86   $ sh -c "../send-signal.sh INT" &
    78   $ hg wait-signal
    87   $ ../wait-signal.sh
    79   interrupted!
    88   interrupted!
    80   [255]
    89   [255]
    81 
    90 
    82   $ cat >> $HGRCPATH << EOF
    91   $ cat >> $HGRCPATH << EOF
    83   > [experimental]
    92   > [experimental]
    84   > nointerrupt-interactiveonly = False
    93   > nointerrupt-interactiveonly = False
    85   > EOF
    94   > EOF
    86 
    95 
    87   $ rm -f $SYNC_FILE $DONE_FILE
    96   $ rm -f $SYNC_FILE $DONE_FILE
    88   $ sh -c "../send-signal.sh INT" &
    97   $ sh -c "../send-signal.sh INT" &
    89   $ hg wait-signal
    98   $ ../wait-signal.sh
    90   shutting down cleanly
    99   shutting down cleanly
    91   press ^C again to terminate immediately (dangerous)
   100   press ^C again to terminate immediately (dangerous)
    92   end of unsafe operation
   101   end of unsafe operation
    93   interrupted!
   102   interrupted!
    94   [255]
   103   [255]