tests/test-transaction-rollback-on-sigpipe.t
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 02 Jul 2021 20:53:23 +0200
changeset 47556 640fdb7fd67b
parent 47555 452795b0b69a
child 47557 ed81f2be5527
permissions -rw-r--r--
test: make sure we hit the SIGPIPE in test-transaction-rollback-on-sigpipe With a coming change, we might not hit the sig pipe without issue and extra line of output. We do this early to make the next change clearer. Differential Revision: https://phab.mercurial-scm.org/D10946

#require bash
Test that, when an hg push is interrupted and the remote side receives SIGPIPE,
the remote hg is able to successfully roll back the transaction.

  $ hg init -q remote
  $ hg clone -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" -q ssh://user@dummy/`pwd`/remote local

  $ pidfile=`pwd`/pidfile
  $ >$pidfile

  $ script() {
  >     cat >"$1"
  >     chmod +x "$1"
  > }

On the remote end, run hg, piping stdout and stderr through processes that we
know the PIDs of. We will later kill these to simulate an ssh client
disconnecting.

  $ killable_pipe=`pwd`/killable_pipe.sh
  $ script $killable_pipe <<EOF
  > #!/usr/bin/env bash
  > echo \$\$ >> $pidfile
  > exec cat
  > EOF

  $ remotecmd=`pwd`/remotecmd.sh
  $ script $remotecmd <<EOF
  > #!/usr/bin/env bash
  > hg "\$@" 1> >($killable_pipe) 2> >($killable_pipe >&2)
  > EOF

In the pretxnchangegroup hook, kill the PIDs recorded above to simulate ssh
disconnecting. Then exit nonzero, to force a transaction rollback.

  $ hook_script=`pwd`/pretxnchangegroup.sh
  $ script $hook_script <<EOF
  > #!/usr/bin/env bash
  > for pid in \$(cat $pidfile) ; do
  >   kill \$pid
  >   while kill -0 \$pid 2>/dev/null ; do
  >     sleep 0.1
  >   done
  > done
  > exit 1
  > EOF

  $ cat >remote/.hg/hgrc <<EOF
  > [hooks]
  > pretxnchangegroup.00-break-things=$hook_script
  > pretxnchangegroup.01-output-things=echo "some remote output to be forward to the closed pipe"
  > EOF

  $ hg --cwd ./remote tip -T '{node|short}\n'
  000000000000
  $ cd local
  $ echo foo > foo ; hg commit -qAm "commit"
  $ hg push -q -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" --remotecmd $remotecmd 2>&1 | grep -v $killable_pipe
  abort: stream ended unexpectedly (got 0 bytes, expected 4)

The remote should be left in a good state
  $ hg --cwd ../remote tip -T '{node|short}\n'
  000000000000
  $ hg --cwd ../remote recover
  no interrupted transaction available
  [1]