Debian Codegraph @

tests/test-transaction-wc-rollback-race.t

raw
1 =======================================================================
2 Check potential race condition around transaction and working copy data
3 =======================================================================
4
5 #testcases bookmarks-in-store bookmarks-wc-level
6
7 The transaction is garanteed to run with the lock, but may runs without the
8 wlock. So if the transaction backup/restore some content related to the
9 working-copy and protected by the wlock, we might run into trouble if another
10 process grab the wlock and modify them.
11
12 This test file is testing various cases where such parallel changes happens to
13 validate the transaction behavior.
14
15 Other is used to get a simple pull source. As pull is a simple way to create
16 transaction without the wlock.
17
18 Setup
19 =====
20
21 Avoid long deadlock
22
23 $ cat << EOF >> $HGRCPATH
24 > [ui]
25 > timeout=10
26 > EOF
27
28 #if bookmarks-in-store
29 $ cat << EOF >> $HGRCPATH
30 > [format]
31 > bookmarks-in-store = yes
32 > EOF
33 #endif
34
35
36 $ hg init repo
37 $ cd repo
38 $ for filename in a b c d e f g h i j k l m; do
39 > echo $filename > default_$filename
40 > hg add default_$filename
41 > hg commit --quiet --message default_$filename
42 > done
43 $ hg bookmark --rev . foo
44 $ hg branch babar
45 marked working directory as branch babar
46 (branches are permanent and global, did you want a bookmark?)
47 $ for filename in a b c d e f g h i j k l m; do
48 > echo $filename > babar_$filename
49 > hg add babar_$filename
50 > hg commit --quiet --message babar_$filename
51 > done
52 $ hg bookmark --rev . bar
53 $ hg up 'desc("default_m")'
54 0 files updated, 0 files merged, 13 files removed, 0 files unresolved
55 $ hg log -G -T '[{branch}] ({bookmarks}) {desc}\n'
56 o [babar] (bar) babar_m
57 |
58 o [babar] () babar_l
59 |
60 o [babar] () babar_k
61 |
62 o [babar] () babar_j
63 |
64 o [babar] () babar_i
65 |
66 o [babar] () babar_h
67 |
68 o [babar] () babar_g
69 |
70 o [babar] () babar_f
71 |
72 o [babar] () babar_e
73 |
74 o [babar] () babar_d
75 |
76 o [babar] () babar_c
77 |
78 o [babar] () babar_b
79 |
80 o [babar] () babar_a
81 |
82 @ [default] (foo) default_m
83 |
84 o [default] () default_l
85 |
86 o [default] () default_k
87 |
88 o [default] () default_j
89 |
90 o [default] () default_i
91 |
92 o [default] () default_h
93 |
94 o [default] () default_g
95 |
96 o [default] () default_f
97 |
98 o [default] () default_e
99 |
100 o [default] () default_d
101 |
102 o [default] () default_c
103 |
104 o [default] () default_b
105 |
106 o [default] () default_a
107
108
109 $ cat << EOF >> ../txn-close.sh
110 > rm -f "$TESTTMP/transaction-continue"
111 > "$RUNTESTDIR/testlib/wait-on-file" 5 "$TESTTMP/transaction-continue" "$TESTTMP/transaction-waiting"
112 > rm -f "$TESTTMP/transaction-waiting"
113 > exit 1
114 > EOF
115
116 $ cat << EOF >> .hg/hgrc
117 > [hooks]
118 > pretxnclose.test = sh "$TESTTMP/txn-close.sh"
119 > EOF
120
121 Check the overall logic is working, the transaction is holding the `lock` , but
122 not the `wlock`, then get aborted on a signal-file.
123
124 $ hg phase --rev 0
125 0: draft
126 $ hg phase --public --rev 0 2> ../log.err &
127 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/transaction-waiting
128 $ echo y | hg --config ui.interactive=yes debuglock --set-wlock
129 ready to release the lock (y)? y
130 $ echo y | hg --config ui.interactive=yes debuglock --set-lock
131 abort: lock is already held
132 [255]
133 $ touch "$TESTTMP/transaction-continue"
134 $ wait
135 $ hg phase --rev 0
136 0: draft
137 $ cat ../log.err
138 abort: pretxnclose.test hook exited with status 1
139
140 Actual testing
141 ==============
142
143 Changing tracked file
144 ---------------------
145
146 $ hg status
147 $ hg phase --public --rev 0 2> ../log.err &
148 $ "$RUNTESTDIR/testlib/wait-on-file" 5 "$TESTTMP/transaction-waiting"
149 $ hg forget default_a
150 $ hg status
151 R default_a
152 $ touch "$TESTTMP/transaction-continue"
153 $ wait
154 $ hg status
155 R default_a
156 $ hg revert --all --quiet
157
158 Changing branch from default
159 ----------------------------
160
161 $ hg branch
162 default
163 $ hg phase --public --rev 0 2> ../log.err &
164 $ "$RUNTESTDIR/testlib/wait-on-file" 5 "$TESTTMP/transaction-waiting"
165 $ hg branch celeste
166 marked working directory as branch celeste
167 $ hg branch
168 celeste
169 $ touch "$TESTTMP/transaction-continue"
170 $ wait
171 $ hg branch
172 celeste
173
174 Changing branch from another one
175 --------------------------------
176
177 $ hg up babar --quiet
178 $ hg branch
179 babar
180 $ hg phase --public --rev 0 2> ../log.err &
181 $ "$RUNTESTDIR/testlib/wait-on-file" 5 "$TESTTMP/transaction-waiting"
182 $ hg branch celeste
183 marked working directory as branch celeste
184 $ hg branch
185 celeste
186 $ touch "$TESTTMP/transaction-continue"
187 $ wait
188 $ hg branch
189 celeste
190
191 updating working copy
192 ---------------------
193
194 $ hg st
195 $ hg log --rev . -T '{desc}\n'
196 babar_m
197 $ hg phase --public --rev 0 2> ../log.err &
198 $ $RUNTESTDIR/testlib/wait-on-file 5 "$TESTTMP/transaction-waiting"
199 $ hg update "parents(.)" --quiet
200 $ hg log --rev . -T '{desc}\n'
201 babar_l
202 $ hg st
203 $ touch "$TESTTMP/transaction-continue"
204 $ wait
205 $ hg log --rev . -T '{desc}\n'
206 babar_l
207 $ hg st
208
209 $ hg purge --no-confirm
210 $ hg up --quiet babar
211
212 Activating a bookmark
213 ---------------------
214 (without going through the bookmark command)
215
216 Show the activation/desactivation pattern that exist without taking the store
217 lock.
218
219 $ hg log -r . -T '= {activebookmark} =\n'
220 = =
221 $ hg up bar
222 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
223 (activating bookmark bar)
224 $ hg log -r . -T '= {activebookmark} =\n'
225 = bar =
226 $ hg up .
227 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
228 (leaving bookmark bar)
229 $ hg log -r . -T '= {activebookmark} =\n'
230 = =
231
232 Activating the bookmark during a transaction
233
234 $ hg up . --quiet
235 $ hg log -r . -T '= {activebookmark} =\n'
236 = =
237 $ hg phase --public --rev 0 2> ../log.err &
238 $ $RUNTESTDIR/testlib/wait-on-file 5 "$TESTTMP/transaction-waiting"
239 $ hg up bar
240 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
241 (activating bookmark bar)
242 $ hg log -r . -T '= {activebookmark} =\n'
243 = bar =
244 $ touch "$TESTTMP/transaction-continue"
245 $ wait
246 $ hg log -r . -T '= {activebookmark} =\n'
247 = bar =
248
249 Deactivating the bookmark
250
251 $ hg up bar --quiet
252 $ hg log -r . -T '= {activebookmark} =\n'
253 = bar =
254 $ hg phase --public --rev 0 2> ../log.err &
255 $ $RUNTESTDIR/testlib/wait-on-file 5 "$TESTTMP/transaction-waiting"
256 $ hg up .
257 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
258 (leaving bookmark bar)
259 $ hg log -r . -T '= {activebookmark} =\n'
260 = =
261 $ touch "$TESTTMP/transaction-continue"
262 $ wait
263 $ hg log -r . -T '= {activebookmark} =\n'
264 = =