##// END OF EJS Templates
test: make sure we hit the SIGPIPE in test-transaction-rollback-on-sigpipe...
marmoute -
r48351:640fdb7f default
parent child Browse files
Show More
@@ -1,65 +1,66 b''
1 #require bash
1 #require bash
2 Test that, when an hg push is interrupted and the remote side receives SIGPIPE,
2 Test that, when an hg push is interrupted and the remote side receives SIGPIPE,
3 the remote hg is able to successfully roll back the transaction.
3 the remote hg is able to successfully roll back the transaction.
4
4
5 $ hg init -q remote
5 $ hg init -q remote
6 $ hg clone -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" -q ssh://user@dummy/`pwd`/remote local
6 $ hg clone -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" -q ssh://user@dummy/`pwd`/remote local
7
7
8 $ pidfile=`pwd`/pidfile
8 $ pidfile=`pwd`/pidfile
9 $ >$pidfile
9 $ >$pidfile
10
10
11 $ script() {
11 $ script() {
12 > cat >"$1"
12 > cat >"$1"
13 > chmod +x "$1"
13 > chmod +x "$1"
14 > }
14 > }
15
15
16 On the remote end, run hg, piping stdout and stderr through processes that we
16 On the remote end, run hg, piping stdout and stderr through processes that we
17 know the PIDs of. We will later kill these to simulate an ssh client
17 know the PIDs of. We will later kill these to simulate an ssh client
18 disconnecting.
18 disconnecting.
19
19
20 $ killable_pipe=`pwd`/killable_pipe.sh
20 $ killable_pipe=`pwd`/killable_pipe.sh
21 $ script $killable_pipe <<EOF
21 $ script $killable_pipe <<EOF
22 > #!/usr/bin/env bash
22 > #!/usr/bin/env bash
23 > echo \$\$ >> $pidfile
23 > echo \$\$ >> $pidfile
24 > exec cat
24 > exec cat
25 > EOF
25 > EOF
26
26
27 $ remotecmd=`pwd`/remotecmd.sh
27 $ remotecmd=`pwd`/remotecmd.sh
28 $ script $remotecmd <<EOF
28 $ script $remotecmd <<EOF
29 > #!/usr/bin/env bash
29 > #!/usr/bin/env bash
30 > hg "\$@" 1> >($killable_pipe) 2> >($killable_pipe >&2)
30 > hg "\$@" 1> >($killable_pipe) 2> >($killable_pipe >&2)
31 > EOF
31 > EOF
32
32
33 In the pretxnchangegroup hook, kill the PIDs recorded above to simulate ssh
33 In the pretxnchangegroup hook, kill the PIDs recorded above to simulate ssh
34 disconnecting. Then exit nonzero, to force a transaction rollback.
34 disconnecting. Then exit nonzero, to force a transaction rollback.
35
35
36 $ hook_script=`pwd`/pretxnchangegroup.sh
36 $ hook_script=`pwd`/pretxnchangegroup.sh
37 $ script $hook_script <<EOF
37 $ script $hook_script <<EOF
38 > #!/usr/bin/env bash
38 > #!/usr/bin/env bash
39 > for pid in \$(cat $pidfile) ; do
39 > for pid in \$(cat $pidfile) ; do
40 > kill \$pid
40 > kill \$pid
41 > while kill -0 \$pid 2>/dev/null ; do
41 > while kill -0 \$pid 2>/dev/null ; do
42 > sleep 0.1
42 > sleep 0.1
43 > done
43 > done
44 > done
44 > done
45 > exit 1
45 > exit 1
46 > EOF
46 > EOF
47
47
48 $ cat >remote/.hg/hgrc <<EOF
48 $ cat >remote/.hg/hgrc <<EOF
49 > [hooks]
49 > [hooks]
50 > pretxnchangegroup.break-things=$hook_script
50 > pretxnchangegroup.00-break-things=$hook_script
51 > pretxnchangegroup.01-output-things=echo "some remote output to be forward to the closed pipe"
51 > EOF
52 > EOF
52
53
53 $ hg --cwd ./remote tip -T '{node|short}\n'
54 $ hg --cwd ./remote tip -T '{node|short}\n'
54 000000000000
55 000000000000
55 $ cd local
56 $ cd local
56 $ echo foo > foo ; hg commit -qAm "commit"
57 $ echo foo > foo ; hg commit -qAm "commit"
57 $ hg push -q -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" --remotecmd $remotecmd 2>&1 | grep -v $killable_pipe
58 $ hg push -q -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" --remotecmd $remotecmd 2>&1 | grep -v $killable_pipe
58 abort: stream ended unexpectedly (got 0 bytes, expected 4)
59 abort: stream ended unexpectedly (got 0 bytes, expected 4)
59
60
60 The remote should be left in a good state
61 The remote should be left in a good state
61 $ hg --cwd ../remote tip -T '{node|short}\n'
62 $ hg --cwd ../remote tip -T '{node|short}\n'
62 000000000000
63 000000000000
63 $ hg --cwd ../remote recover
64 $ hg --cwd ../remote recover
64 no interrupted transaction available
65 no interrupted transaction available
65 [1]
66 [1]
General Comments 0
You need to be logged in to leave comments. Login now