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 <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Oct 11, 2018 at 11:43 UTC c6e5607c56a3333681e6f1e5b8879697be8b94cd
1 file changed +28 -21
t/t1700-split-index.sh
+28 -21
@@ -11,6 +11,13 @@ sane_unset GIT_TEST_SPLIT_INDEX
11 # with those checks, so disable it in this test script.
12 sane_unset GIT_FSMONITOR_TEST
13
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 +
21 test_expect_success 'enable split index' '
22 git config splitIndex.maxPercentChange 100 &&
23 git update-index --split-index &&
@@ -34,7 +41,7 @@ test_expect_success 'enable split index' '
41 '
42
43 test_expect_success 'add one file' '
37 - : >one &&
44 + create_non_racy_file one &&
45 git update-index --add one &&
46 git ls-files --stage >ls-files.actual &&
47 cat >ls-files.expect <<-EOF &&
@@ -86,7 +93,7 @@ test_expect_success 'enable split index again, "one" now belongs to base index"'
93 '
94
95 test_expect_success 'modify original file, base index untouched' '
89 - echo modified >one &&
96 + echo modified | create_non_racy_file one &&
97 git update-index one &&
98 git ls-files --stage >ls-files.actual &&
99 cat >ls-files.expect <<-EOF &&
@@ -105,7 +112,7 @@ test_expect_success 'modify original file, base index untouched' '
112 '
113
114 test_expect_success 'add another file, which stays index' '
108 - : >two &&
115 + create_non_racy_file two &&
116 git update-index --add two &&
117 git ls-files --stage >ls-files.actual &&
118 cat >ls-files.expect <<-EOF &&
@@ -158,7 +165,7 @@ test_expect_success 'remove file in base index' '
165 '
166
167 test_expect_success 'add original file back' '
161 - : >one &&
168 + create_non_racy_file one &&
169 git update-index --add one &&
170 git ls-files --stage >ls-files.actual &&
171 cat >ls-files.expect <<-EOF &&
@@ -177,7 +184,7 @@ test_expect_success 'add original file back' '
184 '
185
186 test_expect_success 'add new file' '
180 - : >two &&
187 + create_non_racy_file two &&
188 git update-index --add two &&
189 git ls-files --stage >actual &&
190 cat >expect <<-EOF &&
@@ -221,7 +228,7 @@ test_expect_success 'rev-parse --shared-index-path' '
228
229 test_expect_success 'set core.splitIndex config variable to true' '
230 git config core.splitIndex true &&
224 - : >three &&
231 + create_non_racy_file three &&
232 git update-index --add three &&
233 git ls-files --stage >ls-files.actual &&
234 cat >ls-files.expect <<-EOF &&
@@ -256,9 +263,9 @@ test_expect_success 'set core.splitIndex config variable to false' '
263 test_cmp expect actual
264 '
265
259 -test_expect_success 'set core.splitIndex config variable to true' '
266 +test_expect_success 'set core.splitIndex config variable back to true' '
267 git config core.splitIndex true &&
261 - : >three &&
268 + create_non_racy_file three &&
269 git update-index --add three &&
270 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
271 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' '
275 deletions:
276 EOF
277 test_cmp expect actual &&
271 - : >four &&
278 + create_non_racy_file four &&
279 git update-index --add four &&
280 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
281 cat >expect <<-EOF &&
@@ -282,7 +289,7 @@ test_expect_success 'set core.splitIndex config variable to true' '
289
290 test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
291 git config --unset splitIndex.maxPercentChange &&
285 - : >five &&
292 + create_non_racy_file five &&
293 git update-index --add five &&
294 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
295 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -292,7 +299,7 @@ test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
299 deletions:
300 EOF
301 test_cmp expect actual &&
295 - : >six &&
302 + create_non_racy_file six &&
303 git update-index --add six &&
304 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
305 cat >expect <<-EOF &&
@@ -306,7 +313,7 @@ test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
313
314 test_expect_success 'check splitIndex.maxPercentChange set to 0' '
315 git config splitIndex.maxPercentChange 0 &&
309 - : >seven &&
316 + create_non_racy_file seven &&
317 git update-index --add seven &&
318 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
319 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -316,7 +323,7 @@ test_expect_success 'check splitIndex.maxPercentChange set to 0' '
323 deletions:
324 EOF
325 test_cmp expect actual &&
319 - : >eight &&
326 + create_non_racy_file eight &&
327 git update-index --add eight &&
328 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
329 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -329,17 +336,17 @@ test_expect_success 'check splitIndex.maxPercentChange set to 0' '
336 '
337
338 test_expect_success 'shared index files expire after 2 weeks by default' '
332 - : >ten &&
339 + create_non_racy_file ten &&
340 git update-index --add ten &&
341 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
342 just_under_2_weeks_ago=$((5-14*86400)) &&
343 test-tool chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
337 - : >eleven &&
344 + create_non_racy_file eleven &&
345 git update-index --add eleven &&
346 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
347 just_over_2_weeks_ago=$((-1-14*86400)) &&
348 test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
342 - : >twelve &&
349 + create_non_racy_file twelve &&
350 git update-index --add twelve &&
351 test $(ls .git/sharedindex.* | wc -l) -le 2
352 '
@@ -347,12 +354,12 @@ test_expect_success 'shared index files expire after 2 weeks by default' '
354 test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
355 git config splitIndex.sharedIndexExpire "16.days.ago" &&
356 test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
350 - : >thirteen &&
357 + create_non_racy_file thirteen &&
358 git update-index --add thirteen &&
359 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
360 just_over_16_days_ago=$((-1-16*86400)) &&
361 test-tool chmtime =$just_over_16_days_ago .git/sharedindex.* &&
355 - : >fourteen &&
362 + create_non_racy_file fourteen &&
363 git update-index --add fourteen &&
364 test $(ls .git/sharedindex.* | wc -l) -le 2
365 '
@@ -361,13 +368,13 @@ test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"
368 git config splitIndex.sharedIndexExpire never &&
369 just_10_years_ago=$((-365*10*86400)) &&
370 test-tool chmtime =$just_10_years_ago .git/sharedindex.* &&
364 - : >fifteen &&
371 + create_non_racy_file fifteen &&
372 git update-index --add fifteen &&
373 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
374 git config splitIndex.sharedIndexExpire now &&
375 just_1_second_ago=-1 &&
376 test-tool chmtime =$just_1_second_ago .git/sharedindex.* &&
370 - : >sixteen &&
377 + create_non_racy_file sixteen &&
378 git update-index --add sixteen &&
379 test $(ls .git/sharedindex.* | wc -l) -le 2
380 '
@@ -382,7 +389,7 @@ do
389 # Create one new shared index file
390 git config core.sharedrepository "$mode" &&
391 git config core.splitIndex true &&
385 - : >one &&
392 + create_non_racy_file one &&
393 git update-index --add one &&
394 echo "$modebits" >expect &&
395 test_modebits .git/index >actual &&