Debian Codegraph @

tests/test-pending.t

raw
1 Verify that pending changesets are seen by pretxn* hooks but not by other
2 processes that access the destination repo while the hooks are running.
3
4 The hooks (python and external) both reject changesets after some think time,
5 during which another process runs pull. Each hook creates a file ('notify') to
6 indicate to the controlling process that it is running; the process removes the
7 file to indicate the hook can terminate.
8
9 init env vars
10
11 $ d=`pwd`
12 $ maxwait=20
13
14 utility to run the test - start a push in the background and run pull
15
16 $ dotest() {
17 > rm -f notify
18 > printf 'push '; hg -R child-push tip --template '{node}\n'
19 > hg -R child-push -q push > push.out 2>&1 &
20 >
21 > # wait for hook to create the notify file
22 > i=$maxwait
23 > while [ ! -f notify -a $i != 0 ]; do
24 > sleep 1
25 > i=`expr $i - 1`
26 > done
27 >
28 > # run pull
29 > hg -R child-pull -q pull
30 > rc=$?
31 >
32 > # tell hook to finish; notify should exist.
33 > rm notify
34 > wait
35 >
36 > cat push.out
37 > printf 'pull '; hg -R child-pull tip --template '{node}\n'
38 > return $rc
39 > }
40
41 python hook
42
43 $ cat <<EOF > reject.py
44 > import os
45 > import time
46 > def rejecthook(ui, repo, hooktype, node, **opts):
47 > ui.write(b'hook %s\\n' % repo[b'tip'].hex())
48 > # create the notify file so caller knows we're running
49 > fpath = os.path.join('$d', 'notify')
50 > f = open(fpath, 'w')
51 > f.close()
52 > # wait for ack - caller should delete the notify file
53 > i = int("$maxwait")
54 > while os.path.exists(fpath) and i > 0:
55 > time.sleep(1)
56 > i -= 1
57 > return True # reject the changesets
58 > EOF
59
60 external hook
61
62 $ cat <<EOF > reject.sh
63 > printf 'hook '; hg tip --template '{node}\\n'
64 > # create the notify file so caller knows we're running
65 > fpath=$d/notify
66 > touch \$fpath
67 > # wait for ack - caller should delete the notify file
68 > i=$maxwait
69 > while [ -f \$fpath -a \$i != 0 ]; do
70 > sleep 1
71 > i=\`expr \$i - 1\`
72 > done
73 > exit 1 # reject the changesets
74 > EOF
75
76 create repos
77
78 $ hg init parent
79 $ hg clone -q parent child-push
80 $ hg clone -q parent child-pull
81 $ echo a > child-push/a
82 $ hg -R child-push add child-push/a
83 $ hg -R child-push commit -m a -d '1000000 0'
84
85 test python hook
86
87 $ cat <<EOF > parent/.hg/hgrc
88 > [extensions]
89 > reject = $d/reject.py
90 > [hooks]
91 > pretxnchangegroup = python:reject.rejecthook
92 > EOF
93
94 $ dotest
95 push 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
96 hook 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
97 transaction abort!
98 rollback completed
99 abort: pretxnchangegroup hook failed
100 pull 0000000000000000000000000000000000000000
101
102 test external hook
103
104 $ cat <<EOF > parent/.hg/hgrc
105 > [hooks]
106 > pretxnchangegroup = sh $d/reject.sh
107 > EOF
108
109 $ dotest
110 push 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
111 hook 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
112 transaction abort!
113 rollback completed
114 abort: pretxnchangegroup hook exited with status 1
115 pull 0000000000000000000000000000000000000000
116
117 Test that pending on transaction without changegroup see the normal changegroup(
118 (issue4609)
119
120 $ cat <<EOF > parent/.hg/hgrc
121 > [hooks]
122 > pretxnchangegroup=
123 > pretxnclose = hg tip -T "tip: {node|short}\n"
124 > [phases]
125 > publishing=False
126 > EOF
127
128 setup
129
130 $ cd parent
131 $ echo a > a
132 $ hg add a
133 $ hg commit -m a
134 tip: cb9a9f314b8b
135
136 actual test
137
138 $ hg phase --public .
139 tip: cb9a9f314b8b