##// END OF EJS Templates
dirstate: check dirstate race condition around status...
marmoute -
r51127:5bf6b801 stable
parent child Browse files
Show More
@@ -1,253 +1,295 b''
1 ==============================================================================
1 ==============================================================================
2 Check potential race conditions between a dirstate's read and other operations
2 Check potential race conditions between a dirstate's read and other operations
3 ==============================================================================
3 ==============================================================================
4
4
5 Some commands, like `hg status`, do not need to take the wlock but need to
5 Some commands, like `hg status`, do not need to take the wlock but need to
6 access dirstate data.
6 access dirstate data.
7 Other commands might update the dirstate data while this happens.
7 Other commands might update the dirstate data while this happens.
8
8
9 This can create issues if repository data is read in the wrong order, or for
9 This can create issues if repository data is read in the wrong order, or for
10 the dirstate-v2 format where the data is contained in multiple files.
10 the dirstate-v2 format where the data is contained in multiple files.
11
11
12 This test file is meant to test various cases where such parallel operations
12 This test file is meant to test various cases where such parallel operations
13 happen and make sure the reading process behaves fine. We do so with a `hg
13 happen and make sure the reading process behaves fine. We do so with a `hg
14 status` command since it is probably the most advanced of such read-only
14 status` command since it is probably the most advanced of such read-only
15 command.
15 command.
16
16
17 It bears simililarity with `tests/test-dirstate-status-race.t ` but tests a
17 It bears simililarity with `tests/test-dirstate-status-race.t ` but tests a
18 different type of race.
18 different type of race.
19
19
20 Setup
20 Setup
21 =====
21 =====
22
22
23 $ directories="dir dir/nested dir2"
23 $ directories="dir dir/nested dir2"
24 $ first_files="dir/nested/a dir/b dir/c dir/d dir2/e f"
24 $ first_files="dir/nested/a dir/b dir/c dir/d dir2/e f"
25 $ second_files="g dir/nested/h dir/i dir/j dir2/k dir2/l dir/nested/m"
25 $ second_files="g dir/nested/h dir/i dir/j dir2/k dir2/l dir/nested/m"
26 $ extra_files="dir/n dir/o p q"
26 $ extra_files="dir/n dir/o p q"
27
27
28 $ hg init reference-repo
28 $ hg init reference-repo
29 $ cd reference-repo
29 $ cd reference-repo
30 $ mkdir -p dir/nested dir2
30 $ mkdir -p dir/nested dir2
31 $ touch -t 200001010000 $first_files $directories
31 $ touch -t 200001010000 $first_files $directories
32 $ hg commit -Aqm "recreate a bunch of files to facilitate dirstate-v2 append"
32 $ hg commit -Aqm "recreate a bunch of files to facilitate dirstate-v2 append"
33 $ touch -t 200001010010 $second_files $directories
33 $ touch -t 200001010010 $second_files $directories
34 $ hg commit -Aqm "more files to have two commit"
34 $ hg commit -Aqm "more files to have two commit"
35 $ hg log -G -v
35 $ hg log -G -v
36 @ changeset: 1:9a86dcbfb938
36 @ changeset: 1:9a86dcbfb938
37 | tag: tip
37 | tag: tip
38 | user: test
38 | user: test
39 | date: Thu Jan 01 00:00:00 1970 +0000
39 | date: Thu Jan 01 00:00:00 1970 +0000
40 | files: dir/i dir/j dir/nested/h dir/nested/m dir2/k dir2/l g
40 | files: dir/i dir/j dir/nested/h dir/nested/m dir2/k dir2/l g
41 | description:
41 | description:
42 | more files to have two commit
42 | more files to have two commit
43 |
43 |
44 |
44 |
45 o changeset: 0:4f23db756b09
45 o changeset: 0:4f23db756b09
46 user: test
46 user: test
47 date: Thu Jan 01 00:00:00 1970 +0000
47 date: Thu Jan 01 00:00:00 1970 +0000
48 files: dir/b dir/c dir/d dir/nested/a dir2/e f
48 files: dir/b dir/c dir/d dir/nested/a dir2/e f
49 description:
49 description:
50 recreate a bunch of files to facilitate dirstate-v2 append
50 recreate a bunch of files to facilitate dirstate-v2 append
51
51
52
52
53 $ hg manifest
53 $ hg manifest
54 dir/b
54 dir/b
55 dir/c
55 dir/c
56 dir/d
56 dir/d
57 dir/i
57 dir/i
58 dir/j
58 dir/j
59 dir/nested/a
59 dir/nested/a
60 dir/nested/h
60 dir/nested/h
61 dir/nested/m
61 dir/nested/m
62 dir2/e
62 dir2/e
63 dir2/k
63 dir2/k
64 dir2/l
64 dir2/l
65 f
65 f
66 g
66 g
67
67
68 Add some unknown files and refresh the dirstate
68 Add some unknown files and refresh the dirstate
69
69
70 $ touch -t 200001010020 $extra_files
70 $ touch -t 200001010020 $extra_files
71 $ hg add dir/o
71 $ hg add dir/o
72 $ hg remove dir/nested/m
72 $ hg remove dir/nested/m
73
73
74 $ hg st --config devel.dirstate.v2.data_update_mode=force-new
74 $ hg st --config devel.dirstate.v2.data_update_mode=force-new
75 A dir/o
75 A dir/o
76 R dir/nested/m
76 R dir/nested/m
77 ? dir/n
77 ? dir/n
78 ? p
78 ? p
79 ? q
79 ? q
80 $ hg debugstate
80 $ hg debugstate
81 n 644 0 2000-01-01 00:00:00 dir/b
81 n 644 0 2000-01-01 00:00:00 dir/b
82 n 644 0 2000-01-01 00:00:00 dir/c
82 n 644 0 2000-01-01 00:00:00 dir/c
83 n 644 0 2000-01-01 00:00:00 dir/d
83 n 644 0 2000-01-01 00:00:00 dir/d
84 n 644 0 2000-01-01 00:10:00 dir/i
84 n 644 0 2000-01-01 00:10:00 dir/i
85 n 644 0 2000-01-01 00:10:00 dir/j
85 n 644 0 2000-01-01 00:10:00 dir/j
86 n 644 0 2000-01-01 00:00:00 dir/nested/a
86 n 644 0 2000-01-01 00:00:00 dir/nested/a
87 n 644 0 2000-01-01 00:10:00 dir/nested/h
87 n 644 0 2000-01-01 00:10:00 dir/nested/h
88 r ?????????????????????????????????? dir/nested/m (glob)
88 r ?????????????????????????????????? dir/nested/m (glob)
89 a ?????????????????????????????????? dir/o (glob)
89 a ?????????????????????????????????? dir/o (glob)
90 n 644 0 2000-01-01 00:00:00 dir2/e
90 n 644 0 2000-01-01 00:00:00 dir2/e
91 n 644 0 2000-01-01 00:10:00 dir2/k
91 n 644 0 2000-01-01 00:10:00 dir2/k
92 n 644 0 2000-01-01 00:10:00 dir2/l
92 n 644 0 2000-01-01 00:10:00 dir2/l
93 n 644 0 2000-01-01 00:00:00 f
93 n 644 0 2000-01-01 00:00:00 f
94 n 644 0 2000-01-01 00:10:00 g
94 n 644 0 2000-01-01 00:10:00 g
95 $ hg debugstate > ../reference
95 $ hg debugstate > ../reference
96 $ cd ..
96 $ cd ..
97
97
98 Actual Testing
98 Actual Testing
99 ==============
99 ==============
100
100
101 Race with a `hg add`
101 Race with a `hg add`
102 -------------------
102 -------------------
103
103
104 $ cp -a reference-repo race-with-add
104 $ cp -a reference-repo race-with-add
105 $ cd race-with-add
105 $ cd race-with-add
106
106
107 spin a `hg status` with some caches to update
107 spin a `hg status` with some caches to update
108
108
109 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
109 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
110 > --config rhg.on-unsupported=abort \
110 > --config rhg.on-unsupported=abort \
111 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
111 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
112 > &
112 > &
113 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
113 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
114
114
115 Add a file
115 Add a file
116
116
117 $ hg add dir/n $d2args
117 $ hg add dir/n $d2args
118 $ touch $TESTTMP/status-race-lock
118 $ touch $TESTTMP/status-race-lock
119 $ wait
119 $ wait
120
120
121 The file should in a "added" state
121 The file should in a "added" state
122
122
123 $ hg status
123 $ hg status
124 A dir/n
124 A dir/n
125 A dir/o
125 A dir/o
126 R dir/nested/m
126 R dir/nested/m
127 ? p
127 ? p
128 ? q
128 ? q
129
129
130 The status process should return a consistent result and not crash.
130 The status process should return a consistent result and not crash.
131
131
132 $ cat $TESTTMP/status-race-lock.out
132 $ cat $TESTTMP/status-race-lock.out
133 A dir/n
133 A dir/n
134 A dir/o
134 A dir/o
135 R dir/nested/m
135 R dir/nested/m
136 ? p
136 ? p
137 ? q
137 ? q
138 $ cat $TESTTMP/status-race-lock.log
138 $ cat $TESTTMP/status-race-lock.log
139
139
140 final cleanup
140 final cleanup
141
141
142 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
142 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
143 $ cd ..
143 $ cd ..
144
144
145 Race with a `hg commit`
145 Race with a `hg commit`
146 -----------------------
146 -----------------------
147
147
148 $ cp -a reference-repo race-with-commit
148 $ cp -a reference-repo race-with-commit
149 $ cd race-with-commit
149 $ cd race-with-commit
150
150
151 spin a `hg status with some cache to update
151 spin a `hg status with some cache to update
152
152
153 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
153 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
154 > --config rhg.on-unsupported=abort \
154 > --config rhg.on-unsupported=abort \
155 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
155 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
156 > &
156 > &
157 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
157 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
158
158
159 Add a do a commit
159 Add a do a commit
160
160
161 $ hg status
161 $ hg status
162 A dir/o
162 A dir/o
163 R dir/nested/m
163 R dir/nested/m
164 ? dir/n
164 ? dir/n
165 ? p
165 ? p
166 ? q
166 ? q
167 $ hg commit -m 'racing commit'
167 $ hg commit -m 'racing commit'
168 $ touch $TESTTMP/status-race-lock
168 $ touch $TESTTMP/status-race-lock
169 $ wait
169 $ wait
170
170
171 commit was created, and status is now clean
171 commit was created, and status is now clean
172
172
173 $ hg log -GT '{node|short} {desc}\n'
173 $ hg log -GT '{node|short} {desc}\n'
174 @ 02a67a77ee9b racing commit
174 @ 02a67a77ee9b racing commit
175 |
175 |
176 o 9a86dcbfb938 more files to have two commit
176 o 9a86dcbfb938 more files to have two commit
177 |
177 |
178 o 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append
178 o 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append
179
179
180 $ hg status
180 $ hg status
181 ? dir/n
181 ? dir/n
182 ? p
182 ? p
183 ? q
183 ? q
184
184
185 The status process should return a consistent result and not crash.
185 The status process should return a consistent result and not crash.
186
186
187 $ cat $TESTTMP/status-race-lock.out
187 $ cat $TESTTMP/status-race-lock.out
188 M dir/o (known-bad-output no-rhg !)
188 M dir/o (known-bad-output no-rhg !)
189 ? dir/n
189 ? dir/n
190 ? p
190 ? p
191 ? q
191 ? q
192 $ cat $TESTTMP/status-race-lock.log
192 $ cat $TESTTMP/status-race-lock.log
193 warning: ignoring unknown working parent 02a67a77ee9b! (known-bad-output no-rhg !)
193 warning: ignoring unknown working parent 02a67a77ee9b! (known-bad-output no-rhg !)
194
194
195 final cleanup
195 final cleanup
196
196
197 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
197 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
198 $ cd ..
198 $ cd ..
199
199
200 Race with a `hg update`
200 Race with a `hg update`
201 -----------------------
201 -----------------------
202
202
203 $ cp -a reference-repo race-with-update
203 $ cp -a reference-repo race-with-update
204 $ cd race-with-update
204 $ cd race-with-update
205
205
206 spin a `hg status` with some caches to update
206 spin a `hg status` with some caches to update
207
207
208 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
208 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
209 > --config rhg.on-unsupported=abort \
209 > --config rhg.on-unsupported=abort \
210 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
210 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
211 > &
211 > &
212 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
212 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
213 do an update
213 do an update
214
214
215 $ hg status
215 $ hg status
216 A dir/o
216 A dir/o
217 R dir/nested/m
217 R dir/nested/m
218 ? dir/n
218 ? dir/n
219 ? p
219 ? p
220 ? q
220 ? q
221 $ hg log -GT '{node|short} {desc}\n'
221 $ hg log -GT '{node|short} {desc}\n'
222 @ 9a86dcbfb938 more files to have two commit
222 @ 9a86dcbfb938 more files to have two commit
223 |
223 |
224 o 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append
224 o 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append
225
225
226 $ hg update --merge .^
226 $ hg update --merge .^
227 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
227 0 files updated, 0 files merged, 6 files removed, 0 files unresolved
228 $ touch $TESTTMP/status-race-lock
228 $ touch $TESTTMP/status-race-lock
229 $ wait
229 $ wait
230 $ hg log -GT '{node|short} {desc}\n'
230 $ hg log -GT '{node|short} {desc}\n'
231 o 9a86dcbfb938 more files to have two commit
231 o 9a86dcbfb938 more files to have two commit
232 |
232 |
233 @ 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append
233 @ 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append
234
234
235 $ hg status
235 $ hg status
236 A dir/o
236 A dir/o
237 ? dir/n
237 ? dir/n
238 ? p
238 ? p
239 ? q
239 ? q
240
240
241 The status process should return a consistent result and not crash.
241 The status process should return a consistent result and not crash.
242
242
243 $ cat $TESTTMP/status-race-lock.out
243 $ cat $TESTTMP/status-race-lock.out
244 A dir/o
244 A dir/o
245 ? dir/n
245 ? dir/n
246 ? p
246 ? p
247 ? q
247 ? q
248 $ cat $TESTTMP/status-race-lock.log
248 $ cat $TESTTMP/status-race-lock.log
249
249
250 final cleanup
250 final cleanup
251
251
252 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
252 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
253 $ cd ..
253 $ cd ..
254
255 Race with a cache updating `hg status`
256 --------------------------------------
257
258 It is interesting to race with "read-only" operation (that still update its cache)
259
260 $ cp -a reference-repo race-with-status
261 $ cd race-with-status
262
263 spin a `hg status` with some caches to update
264
265 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
266 > --config rhg.on-unsupported=abort \
267 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
268 > &
269 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
270 do an update
271
272 $ touch -t 200001020006 f
273 $ hg status
274 A dir/o
275 R dir/nested/m
276 ? dir/n
277 ? p
278 ? q
279 $ touch $TESTTMP/status-race-lock
280 $ wait
281
282 The status process should return a consistent result and not crash.
283
284 $ cat $TESTTMP/status-race-lock.out
285 A dir/o
286 R dir/nested/m
287 ? dir/n
288 ? p
289 ? q
290 $ cat $TESTTMP/status-race-lock.log
291
292 final cleanup
293
294 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
295 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now