Skip to content

Commit c6e5607

Browse files
szedergitster
authored andcommitted
t1700-split-index: date back files to avoid racy situations
't1700-split-index.sh' checks that the index was split correctly under various circumstances and that all the different ways to turn the split index feature on and off work correctly. To do so, most of its tests use 'test-tool dump-split-index' to see which files have their cache entries in the split index. All these tests assume that all cache entries are written to the shared index (called "base" throughout these tests) when a new shared index is created. This is an implementation detail: most git commands (basically all except 'git update-index') don't care or know at all about split index or whether a cache entry is stored in the split or shared index. As demonstrated in the previous patch, refreshing a split index is prone to a variant of the classic racy git issue. The next patch will fix this issue, but while doing so it will also slightly change this behaviour: only cache entries with mtime in the past will be written only to the newly created shared index, but racily clean cache entries will be written to the new split index (with smudged stat data). While this upcoming change won't at all affect any git commands, it will violate the above mentioned assumption of 't1700's tests. Since these tests create or modify files and create or refresh the split index in rapid succession, there are plenty of racily clean cache entries to be dealt with, which will then be written to the new split indexes, and, ultimately, will cause several tests in 't1700' to fail. Let's prepare 't1700-split-index.sh' for this upcoming change and modify its tests to avoid racily clean files by backdating the mtime of any file modifications (and since a lot of tests create or modify files, encapsulate it into a helper function). Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 74e8add commit c6e5607

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

t/t1700-split-index.sh

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ sane_unset GIT_TEST_SPLIT_INDEX
1111
# with those checks, so disable it in this test script.
1212
sane_unset GIT_FSMONITOR_TEST
1313

14+
# Create a file named as $1 with content read from stdin.
15+
# Set the file's mtime to a few seconds in the past to avoid racy situations.
16+
create_non_racy_file () {
17+
cat >"$1" &&
18+
test-tool chmtime =-5 "$1"
19+
}
20+
1421
test_expect_success 'enable split index' '
1522
git config splitIndex.maxPercentChange 100 &&
1623
git update-index --split-index &&
@@ -34,7 +41,7 @@ test_expect_success 'enable split index' '
3441
'
3542

3643
test_expect_success 'add one file' '
37-
: >one &&
44+
create_non_racy_file one &&
3845
git update-index --add one &&
3946
git ls-files --stage >ls-files.actual &&
4047
cat >ls-files.expect <<-EOF &&
@@ -86,7 +93,7 @@ test_expect_success 'enable split index again, "one" now belongs to base index"'
8693
'
8794

8895
test_expect_success 'modify original file, base index untouched' '
89-
echo modified >one &&
96+
echo modified | create_non_racy_file one &&
9097
git update-index one &&
9198
git ls-files --stage >ls-files.actual &&
9299
cat >ls-files.expect <<-EOF &&
@@ -105,7 +112,7 @@ test_expect_success 'modify original file, base index untouched' '
105112
'
106113

107114
test_expect_success 'add another file, which stays index' '
108-
: >two &&
115+
create_non_racy_file two &&
109116
git update-index --add two &&
110117
git ls-files --stage >ls-files.actual &&
111118
cat >ls-files.expect <<-EOF &&
@@ -158,7 +165,7 @@ test_expect_success 'remove file in base index' '
158165
'
159166

160167
test_expect_success 'add original file back' '
161-
: >one &&
168+
create_non_racy_file one &&
162169
git update-index --add one &&
163170
git ls-files --stage >ls-files.actual &&
164171
cat >ls-files.expect <<-EOF &&
@@ -177,7 +184,7 @@ test_expect_success 'add original file back' '
177184
'
178185

179186
test_expect_success 'add new file' '
180-
: >two &&
187+
create_non_racy_file two &&
181188
git update-index --add two &&
182189
git ls-files --stage >actual &&
183190
cat >expect <<-EOF &&
@@ -221,7 +228,7 @@ test_expect_success 'rev-parse --shared-index-path' '
221228

222229
test_expect_success 'set core.splitIndex config variable to true' '
223230
git config core.splitIndex true &&
224-
: >three &&
231+
create_non_racy_file three &&
225232
git update-index --add three &&
226233
git ls-files --stage >ls-files.actual &&
227234
cat >ls-files.expect <<-EOF &&
@@ -256,9 +263,9 @@ test_expect_success 'set core.splitIndex config variable to false' '
256263
test_cmp expect actual
257264
'
258265

259-
test_expect_success 'set core.splitIndex config variable to true' '
266+
test_expect_success 'set core.splitIndex config variable back to true' '
260267
git config core.splitIndex true &&
261-
: >three &&
268+
create_non_racy_file three &&
262269
git update-index --add three &&
263270
BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
264271
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -268,7 +275,7 @@ test_expect_success 'set core.splitIndex config variable to true' '
268275
deletions:
269276
EOF
270277
test_cmp expect actual &&
271-
: >four &&
278+
create_non_racy_file four &&
272279
git update-index --add four &&
273280
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
274281
cat >expect <<-EOF &&
@@ -282,7 +289,7 @@ test_expect_success 'set core.splitIndex config variable to true' '
282289

283290
test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
284291
git config --unset splitIndex.maxPercentChange &&
285-
: >five &&
292+
create_non_racy_file five &&
286293
git update-index --add five &&
287294
BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
288295
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -292,7 +299,7 @@ test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
292299
deletions:
293300
EOF
294301
test_cmp expect actual &&
295-
: >six &&
302+
create_non_racy_file six &&
296303
git update-index --add six &&
297304
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
298305
cat >expect <<-EOF &&
@@ -306,7 +313,7 @@ test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
306313

307314
test_expect_success 'check splitIndex.maxPercentChange set to 0' '
308315
git config splitIndex.maxPercentChange 0 &&
309-
: >seven &&
316+
create_non_racy_file seven &&
310317
git update-index --add seven &&
311318
BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
312319
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -316,7 +323,7 @@ test_expect_success 'check splitIndex.maxPercentChange set to 0' '
316323
deletions:
317324
EOF
318325
test_cmp expect actual &&
319-
: >eight &&
326+
create_non_racy_file eight &&
320327
git update-index --add eight &&
321328
BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
322329
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -329,30 +336,30 @@ test_expect_success 'check splitIndex.maxPercentChange set to 0' '
329336
'
330337

331338
test_expect_success 'shared index files expire after 2 weeks by default' '
332-
: >ten &&
339+
create_non_racy_file ten &&
333340
git update-index --add ten &&
334341
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
335342
just_under_2_weeks_ago=$((5-14*86400)) &&
336343
test-tool chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
337-
: >eleven &&
344+
create_non_racy_file eleven &&
338345
git update-index --add eleven &&
339346
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
340347
just_over_2_weeks_ago=$((-1-14*86400)) &&
341348
test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
342-
: >twelve &&
349+
create_non_racy_file twelve &&
343350
git update-index --add twelve &&
344351
test $(ls .git/sharedindex.* | wc -l) -le 2
345352
'
346353

347354
test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
348355
git config splitIndex.sharedIndexExpire "16.days.ago" &&
349356
test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
350-
: >thirteen &&
357+
create_non_racy_file thirteen &&
351358
git update-index --add thirteen &&
352359
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
353360
just_over_16_days_ago=$((-1-16*86400)) &&
354361
test-tool chmtime =$just_over_16_days_ago .git/sharedindex.* &&
355-
: >fourteen &&
362+
create_non_racy_file fourteen &&
356363
git update-index --add fourteen &&
357364
test $(ls .git/sharedindex.* | wc -l) -le 2
358365
'
@@ -361,13 +368,13 @@ test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"
361368
git config splitIndex.sharedIndexExpire never &&
362369
just_10_years_ago=$((-365*10*86400)) &&
363370
test-tool chmtime =$just_10_years_ago .git/sharedindex.* &&
364-
: >fifteen &&
371+
create_non_racy_file fifteen &&
365372
git update-index --add fifteen &&
366373
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
367374
git config splitIndex.sharedIndexExpire now &&
368375
just_1_second_ago=-1 &&
369376
test-tool chmtime =$just_1_second_ago .git/sharedindex.* &&
370-
: >sixteen &&
377+
create_non_racy_file sixteen &&
371378
git update-index --add sixteen &&
372379
test $(ls .git/sharedindex.* | wc -l) -le 2
373380
'
@@ -382,7 +389,7 @@ do
382389
# Create one new shared index file
383390
git config core.sharedrepository "$mode" &&
384391
git config core.splitIndex true &&
385-
: >one &&
392+
create_non_racy_file one &&
386393
git update-index --add one &&
387394
echo "$modebits" >expect &&
388395
test_modebits .git/index >actual &&

0 commit comments

Comments
 (0)