Mercurial > hg
annotate tests/test-transaction-rollback-on-sigpipe.t @ 45736:2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
When an hg push is interrupted with C-c, the remote [hg serve] command
receives SIGPIPE.
If a pretxnchangegroup hook fails, the remote hg then tries to
rollback the transaction. It begins by printing "transaction
abort!\n". This returns EPIPE, but ui.py ignores that error.
In python3 (but not python2), this "transaction abort!\n" message
stays in a buffer, so future flushes of stderr will try to print the
message again, and so those flushes will also hit EPIPE.
This test demonstrates such a case where this EPIPE causes the
transaction rollback to fail, leaving behind an abandoned transaction.
Differential Revision: https://phab.mercurial-scm.org/D9151
author | Mitchell Plamann <mplamann@janestreet.com> |
---|---|
date | Mon, 05 Oct 2020 13:23:16 -0400 |
parents | |
children | b3e8d8e4a40d |
rev | line source |
---|---|
45736
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
1 Test that, when an hg push is interrupted and the remote side recieves SIGPIPE, |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
2 the remote hg is able to successfully roll back the transaction. |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
3 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
4 $ hg init -q remote |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
5 $ hg clone -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" -q ssh://user@dummy/`pwd`/remote local |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
6 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
7 $ check_for_abandoned_transaction() { |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
8 > [[ -f $TESTTMP/remote/.hg/store/journal ]] && echo "Abandoned transaction!" |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
9 > } |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
10 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
11 $ pidfile=`pwd`/pidfile |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
12 $ >$pidfile |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
13 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
14 $ script() { |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
15 > cat >"$1" |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
16 > chmod +x "$1" |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
17 > } |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
18 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
19 On the remote end, run hg, piping stdout and stderr through processes that we |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
20 know the PIDs of. We will later kill these to simulate an ssh client |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
21 disconnecting. |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
22 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
23 $ killable_pipe=`pwd`/killable_pipe.sh |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
24 $ script $killable_pipe <<EOF |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
25 > #!/bin/bash |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
26 > echo \$\$ >> $pidfile |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
27 > exec cat |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
28 > EOF |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
29 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
30 $ remotecmd=`pwd`/remotecmd.sh |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
31 $ script $remotecmd <<EOF |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
32 > #!/bin/bash |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
33 > hg "\$@" 1> >($killable_pipe) 2> >($killable_pipe >&2) |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
34 > EOF |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
35 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
36 In the pretxnchangegroup hook, kill the PIDs recorded above to simulate ssh |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
37 disconnecting. Then exit nonzero, to force a transaction rollback. |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
38 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
39 $ hook_script=`pwd`/pretxnchangegroup.sh |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
40 $ script $hook_script <<EOF |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
41 > #!/bin/bash |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
42 > for pid in \$(cat $pidfile) ; do |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
43 > kill \$pid |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
44 > while kill -0 \$pid 2>/dev/null ; do |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
45 > sleep 0.1 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
46 > done |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
47 > done |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
48 > exit 1 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
49 > EOF |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
50 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
51 $ cat >remote/.hg/hgrc <<EOF |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
52 > [hooks] |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
53 > pretxnchangegroup.break-things=$hook_script |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
54 > EOF |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
55 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
56 $ cd local |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
57 $ echo foo > foo ; hg commit -qAm "commit" |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
58 $ hg push -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" --remotecmd $remotecmd 2>&1 | grep -v $killable_pipe |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
59 pushing to ssh://user@dummy/$TESTTMP/remote |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
60 searching for changes |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
61 remote: adding changesets |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
62 remote: adding manifests |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
63 remote: adding file changes |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
64 abort: stream ended unexpectedly (got 0 bytes, expected 4) |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
65 |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
66 $ check_for_abandoned_transaction |
2c6b054e22d0
test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression
Mitchell Plamann <mplamann@janestreet.com>
parents:
diff
changeset
|
67 Abandoned transaction! |