| 1 |
============================================================================== |
| 2 |
Check potential race conditions between a dirstate's read and other operations |
| 3 |
============================================================================== |
| 4 |
|
| 5 |
#testcases dirstate-v1 dirstate-v2-append dirstate-v2-rewrite |
| 6 |
#testcases pre-all-read pre-some-read |
| 7 |
|
| 8 |
Some commands, like `hg status`, do not need to take the wlock but need to |
| 9 |
access dirstate data. |
| 10 |
Other commands might update the dirstate data while this happens. |
| 11 |
|
| 12 |
This can create issues if repository data is read in the wrong order, or for |
| 13 |
the dirstate-v2 format where the data is contained in multiple files. |
| 14 |
|
| 15 |
This test file is meant to test various cases where such parallel operations |
| 16 |
happen and make sure the reading process behaves fine. We do so with a `hg |
| 17 |
status` command since it is probably the most advanced of such read-only |
| 18 |
command. |
| 19 |
|
| 20 |
It bears simililarity with `tests/test-dirstate-status-race.t ` but tests a |
| 21 |
different type of race. |
| 22 |
|
| 23 |
Setup |
| 24 |
===== |
| 25 |
|
| 26 |
$ cat >> $HGRCPATH << EOF |
| 27 |
> [storage] |
| 28 |
> dirstate-v2.slow-path=allow |
| 29 |
> EOF |
| 30 |
|
| 31 |
#if no-dirstate-v1 |
| 32 |
$ cat >> $HGRCPATH << EOF |
| 33 |
> [format] |
| 34 |
> use-dirstate-v2=yes |
| 35 |
> EOF |
| 36 |
#else |
| 37 |
$ cat >> $HGRCPATH << EOF |
| 38 |
> [format] |
| 39 |
> use-dirstate-v2=no |
| 40 |
> EOF |
| 41 |
#endif |
| 42 |
|
| 43 |
#if dirstate-v2-rewrite |
| 44 |
$ d2args="--config devel.dirstate.v2.data_update_mode=force-new" |
| 45 |
#endif |
| 46 |
#if dirstate-v2-append |
| 47 |
$ d2args="--config devel.dirstate.v2.data_update_mode=force-append" |
| 48 |
#endif |
| 49 |
|
| 50 |
|
| 51 |
#if dirstate-v1 |
| 52 |
$ cfg="devel.sync.dirstate.pre-read-file" |
| 53 |
#else |
| 54 |
#if pre-all-read |
| 55 |
$ cfg="devel.sync.dirstate.pre-read-file" |
| 56 |
#else |
| 57 |
$ cfg="devel.sync.dirstate.post-docket-read-file" |
| 58 |
#endif |
| 59 |
#endif |
| 60 |
|
| 61 |
$ directories="dir dir/nested dir2" |
| 62 |
$ first_files="dir/nested/a dir/b dir/c dir/d dir2/e f" |
| 63 |
$ second_files="g dir/nested/h dir/i dir/j dir2/k dir2/l dir/nested/m" |
| 64 |
$ extra_files="dir/n dir/o p q" |
| 65 |
|
| 66 |
$ hg init reference-repo |
| 67 |
$ cd reference-repo |
| 68 |
$ mkdir -p dir/nested dir2 |
| 69 |
$ touch -t 200001010000 $first_files $directories |
| 70 |
$ hg commit -Aqm "recreate a bunch of files to facilitate dirstate-v2 append" |
| 71 |
$ touch -t 200001010010 $second_files $directories |
| 72 |
$ hg commit -Aqm "more files to have two commit" |
| 73 |
$ hg log -G -v |
| 74 |
@ changeset: 1:9a86dcbfb938 |
| 75 |
| tag: tip |
| 76 |
| user: test |
| 77 |
| date: Thu Jan 01 00:00:00 1970 +0000 |
| 78 |
| files: dir/i dir/j dir/nested/h dir/nested/m dir2/k dir2/l g |
| 79 |
| description: |
| 80 |
| more files to have two commit |
| 81 |
| |
| 82 |
| |
| 83 |
o changeset: 0:4f23db756b09 |
| 84 |
user: test |
| 85 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 86 |
files: dir/b dir/c dir/d dir/nested/a dir2/e f |
| 87 |
description: |
| 88 |
recreate a bunch of files to facilitate dirstate-v2 append |
| 89 |
|
| 90 |
|
| 91 |
$ hg manifest |
| 92 |
dir/b |
| 93 |
dir/c |
| 94 |
dir/d |
| 95 |
dir/i |
| 96 |
dir/j |
| 97 |
dir/nested/a |
| 98 |
dir/nested/h |
| 99 |
dir/nested/m |
| 100 |
dir2/e |
| 101 |
dir2/k |
| 102 |
dir2/l |
| 103 |
f |
| 104 |
g |
| 105 |
|
| 106 |
Add some unknown files and refresh the dirstate |
| 107 |
|
| 108 |
$ touch -t 200001010020 $extra_files |
| 109 |
$ hg add dir/o |
| 110 |
$ hg remove dir/nested/m |
| 111 |
|
| 112 |
$ hg st --config devel.dirstate.v2.data_update_mode=force-new |
| 113 |
A dir/o |
| 114 |
R dir/nested/m |
| 115 |
? dir/n |
| 116 |
? p |
| 117 |
? q |
| 118 |
$ hg debugstate |
| 119 |
n 644 0 2000-01-01 00:00:00 dir/b |
| 120 |
n 644 0 2000-01-01 00:00:00 dir/c |
| 121 |
n 644 0 2000-01-01 00:00:00 dir/d |
| 122 |
n 644 0 2000-01-01 00:10:00 dir/i |
| 123 |
n 644 0 2000-01-01 00:10:00 dir/j |
| 124 |
n 644 0 2000-01-01 00:00:00 dir/nested/a |
| 125 |
n 644 0 2000-01-01 00:10:00 dir/nested/h |
| 126 |
r ?????????????????????????????????? dir/nested/m (glob) |
| 127 |
a ?????????????????????????????????? dir/o (glob) |
| 128 |
n 644 0 2000-01-01 00:00:00 dir2/e |
| 129 |
n 644 0 2000-01-01 00:10:00 dir2/k |
| 130 |
n 644 0 2000-01-01 00:10:00 dir2/l |
| 131 |
n 644 0 2000-01-01 00:00:00 f |
| 132 |
n 644 0 2000-01-01 00:10:00 g |
| 133 |
$ hg debugstate > ../reference |
| 134 |
$ cd .. |
| 135 |
|
| 136 |
Actual Testing |
| 137 |
============== |
| 138 |
|
| 139 |
Race with a `hg add` |
| 140 |
------------------- |
| 141 |
|
| 142 |
$ cp -a reference-repo race-with-add |
| 143 |
$ cd race-with-add |
| 144 |
|
| 145 |
spin a `hg status` with some caches to update |
| 146 |
|
| 147 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 148 |
> --config rhg.on-unsupported=abort \ |
| 149 |
> --config ${cfg}=$TESTTMP/status-race-lock \ |
| 150 |
> & |
| 151 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 152 |
|
| 153 |
Add a file |
| 154 |
|
| 155 |
$ hg $d2args add dir/n |
| 156 |
$ touch $TESTTMP/status-race-lock |
| 157 |
$ wait |
| 158 |
|
| 159 |
The file should in a "added" state |
| 160 |
|
| 161 |
$ hg status |
| 162 |
A dir/n |
| 163 |
A dir/o |
| 164 |
R dir/nested/m |
| 165 |
? p |
| 166 |
? q |
| 167 |
|
| 168 |
The status process should return a consistent result and not crash. |
| 169 |
|
| 170 |
#if rust dirstate-v2-append pre-some-read |
| 171 |
$ cat $TESTTMP/status-race-lock.out |
| 172 |
A dir/o |
| 173 |
R dir/nested/m |
| 174 |
? dir/n |
| 175 |
? p |
| 176 |
? q |
| 177 |
#else |
| 178 |
$ cat $TESTTMP/status-race-lock.out |
| 179 |
A dir/n |
| 180 |
A dir/o |
| 181 |
R dir/nested/m |
| 182 |
? p |
| 183 |
? q |
| 184 |
#endif |
| 185 |
$ cat $TESTTMP/status-race-lock.log |
| 186 |
|
| 187 |
final cleanup |
| 188 |
|
| 189 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 190 |
$ cd .. |
| 191 |
|
| 192 |
Race with a `hg commit` |
| 193 |
----------------------- |
| 194 |
|
| 195 |
$ cp -a reference-repo race-with-commit |
| 196 |
$ cd race-with-commit |
| 197 |
|
| 198 |
$ hg status |
| 199 |
A dir/o |
| 200 |
R dir/nested/m |
| 201 |
? dir/n |
| 202 |
? p |
| 203 |
? q |
| 204 |
|
| 205 |
spin a `hg status with some cache to update |
| 206 |
|
| 207 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 208 |
> --config rhg.on-unsupported=abort \ |
| 209 |
> --config ${cfg}=$TESTTMP/status-race-lock \ |
| 210 |
> & |
| 211 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 212 |
|
| 213 |
Add a do a commit |
| 214 |
|
| 215 |
$ hg $d2args commit -m 'racing commit' |
| 216 |
$ touch $TESTTMP/status-race-lock |
| 217 |
$ wait |
| 218 |
|
| 219 |
commit was created, and status is now clean |
| 220 |
|
| 221 |
$ hg log -GT '{node|short} {desc}\n' |
| 222 |
@ 02a67a77ee9b racing commit |
| 223 |
| |
| 224 |
o 9a86dcbfb938 more files to have two commit |
| 225 |
| |
| 226 |
o 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append |
| 227 |
|
| 228 |
$ hg status |
| 229 |
? dir/n |
| 230 |
? p |
| 231 |
? q |
| 232 |
|
| 233 |
The status process should return a consistent result and not crash. |
| 234 |
|
| 235 |
(The "pre-commit" state is only visible to (any) rust variant because the pure |
| 236 |
python implementation always rewrites, so we are never really in the "-append" |
| 237 |
case). |
| 238 |
|
| 239 |
$ cat $TESTTMP/status-race-lock.out |
| 240 |
A dir/o (dirstate-v2-append pre-some-read rust !) |
| 241 |
R dir/nested/m (dirstate-v2-append pre-some-read rust !) |
| 242 |
? dir/n |
| 243 |
? p |
| 244 |
? q |
| 245 |
|
| 246 |
final cleanup |
| 247 |
|
| 248 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 249 |
$ cd .. |
| 250 |
|
| 251 |
Race with a `hg update` |
| 252 |
----------------------- |
| 253 |
|
| 254 |
$ cp -a reference-repo race-with-update |
| 255 |
$ cd race-with-update |
| 256 |
|
| 257 |
$ hg status |
| 258 |
A dir/o |
| 259 |
R dir/nested/m |
| 260 |
? dir/n |
| 261 |
? p |
| 262 |
? q |
| 263 |
$ hg log -GT '{node|short} {desc}\n' |
| 264 |
@ 9a86dcbfb938 more files to have two commit |
| 265 |
| |
| 266 |
o 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append |
| 267 |
|
| 268 |
(double check the working copy location before and after the update+concurrent status) |
| 269 |
$ hg log -T '{node|short}\n' --rev "." |
| 270 |
9a86dcbfb938 |
| 271 |
(update destination) |
| 272 |
$ hg log -T '{node|short}\n' --rev ".~1" |
| 273 |
4f23db756b09 |
| 274 |
|
| 275 |
spin a `hg status` with some caches to update |
| 276 |
|
| 277 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 278 |
> --config rhg.on-unsupported=abort \ |
| 279 |
> --config ${cfg}=$TESTTMP/status-race-lock \ |
| 280 |
> & |
| 281 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 282 |
do an update |
| 283 |
|
| 284 |
$ hg $d2args update --merge ".~1" |
| 285 |
0 files updated, 0 files merged, 6 files removed, 0 files unresolved |
| 286 |
$ touch $TESTTMP/status-race-lock |
| 287 |
$ wait |
| 288 |
(the working copy should have been updated) |
| 289 |
$ hg log -T '{node|short}\n' --rev "." |
| 290 |
4f23db756b09 |
| 291 |
$ hg log -GT '{node|short} {desc}\n' |
| 292 |
o 9a86dcbfb938 more files to have two commit |
| 293 |
| |
| 294 |
@ 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append |
| 295 |
|
| 296 |
$ hg status |
| 297 |
A dir/o |
| 298 |
? dir/n |
| 299 |
? p |
| 300 |
? q |
| 301 |
|
| 302 |
The status process should return a consistent result and not crash. |
| 303 |
|
| 304 |
#if rust dirstate-v2-append pre-some-read |
| 305 |
$ cat $TESTTMP/status-race-lock.out |
| 306 |
A dir/o |
| 307 |
R dir/nested/m |
| 308 |
! dir/i |
| 309 |
! dir/j |
| 310 |
! dir/nested/h |
| 311 |
! dir2/k |
| 312 |
! dir2/l |
| 313 |
! g |
| 314 |
? dir/n |
| 315 |
? p |
| 316 |
? q |
| 317 |
#else |
| 318 |
$ cat $TESTTMP/status-race-lock.out |
| 319 |
A dir/o |
| 320 |
? dir/n |
| 321 |
? p |
| 322 |
? q |
| 323 |
#endif |
| 324 |
$ cat $TESTTMP/status-race-lock.log |
| 325 |
|
| 326 |
final cleanup |
| 327 |
|
| 328 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 329 |
$ cd .. |
| 330 |
|
| 331 |
Race with a cache updating `hg status` |
| 332 |
-------------------------------------- |
| 333 |
|
| 334 |
It is interesting to race with "read-only" operation (that still update its cache) |
| 335 |
|
| 336 |
$ cp -a reference-repo race-with-status |
| 337 |
$ cd race-with-status |
| 338 |
|
| 339 |
spin a `hg status` with some caches to update |
| 340 |
|
| 341 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 342 |
> --config rhg.on-unsupported=abort \ |
| 343 |
> --config ${cfg}=$TESTTMP/status-race-lock \ |
| 344 |
> & |
| 345 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 346 |
do an update |
| 347 |
|
| 348 |
$ touch -t 200001020006 f |
| 349 |
$ hg $d2args status |
| 350 |
A dir/o |
| 351 |
R dir/nested/m |
| 352 |
? dir/n |
| 353 |
? p |
| 354 |
? q |
| 355 |
$ touch $TESTTMP/status-race-lock |
| 356 |
$ wait |
| 357 |
|
| 358 |
The status process should return a consistent result and not crash. |
| 359 |
|
| 360 |
$ cat $TESTTMP/status-race-lock.out |
| 361 |
A dir/o |
| 362 |
R dir/nested/m |
| 363 |
? dir/n |
| 364 |
? p |
| 365 |
? q |
| 366 |
$ cat $TESTTMP/status-race-lock.log |
| 367 |
|
| 368 |
final cleanup |
| 369 |
|
| 370 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 371 |
$ cd .. |