t7063: mtime-mangling instead of delays in untracked cache testing

The untracked cache test uses an avoid_racy function to deal with an mtime-resolution challenge in testing: If an untracked cache entry's mtime falls in the same second as the mtime of the index the untracked cache was stored in, then it cannot be trusted. Explicitly delaying tests is a simple effective strategy to avoid these issues, but should be avoided where possible. Switch from a delay-based strategy to instead backdating all file changes using test-tool chmtime, where that is an option, to shave 9 seconds off the test run time. Don't update test cases that delay for other reasons, for now at least (4 seconds). Signed-off-by: Tao Klerks <tao@klerks.biz> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tao Klerks committed Mar 2, 2022 at 06:05 UTC 9ba83ebfda1137ad7a4d677e6bef57e345288804
1 file changed +9 -12
t/t7063-status-untracked-cache.sh
+9 -12
@@ -90,6 +90,9 @@ test_expect_success 'setup' '
90 cd worktree &&
91 mkdir done dtwo dthree &&
92 touch one two three done/one dtwo/two dthree/three &&
93 + test-tool chmtime =-300 one two three done/one dtwo/two dthree/three &&
94 + test-tool chmtime =-300 done dtwo dthree &&
95 + test-tool chmtime =-300 . &&
96 git add one two done/one &&
97 : >.git/info/exclude &&
98 git update-index --untracked-cache &&
@@ -142,7 +145,6 @@ two
145 EOF
146
147 test_expect_success 'status first time (empty cache)' '
145 - avoid_racy &&
148 : >../trace.output &&
149 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
150 git status --porcelain >../actual &&
@@ -166,7 +168,6 @@ test_expect_success 'untracked cache after first status' '
168 '
169
170 test_expect_success 'status second time (fully populated cache)' '
169 - avoid_racy &&
171 : >../trace.output &&
172 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
173 git status --porcelain >../actual &&
@@ -190,8 +191,8 @@ test_expect_success 'untracked cache after second status' '
191 '
192
193 test_expect_success 'modify in root directory, one dir invalidation' '
193 - avoid_racy &&
194 : >four &&
195 + test-tool chmtime =-240 four &&
196 : >../trace.output &&
197 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
198 git status --porcelain >../actual &&
@@ -241,7 +242,6 @@ EOF
242 '
243
244 test_expect_success 'new .gitignore invalidates recursively' '
244 - avoid_racy &&
245 echo four >.gitignore &&
246 : >../trace.output &&
247 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
@@ -292,7 +292,6 @@ EOF
292 '
293
294 test_expect_success 'new info/exclude invalidates everything' '
295 - avoid_racy &&
295 echo three >>.git/info/exclude &&
296 : >../trace.output &&
297 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
@@ -520,14 +519,14 @@ test_expect_success 'create/modify files, some of which are gitignored' '
519 echo three >done/three && # three is gitignored
520 echo four >done/four && # four is gitignored at a higher level
521 echo five >done/five && # five is not gitignored
523 - echo test >base && #we need to ensure that the root dir is touched
524 - rm base &&
522 + test-tool chmtime =-180 done/two done/three done/four done/five done &&
523 + # we need to ensure that the root dir is touched (in the past);
524 + test-tool chmtime =-180 . &&
525 sync_mtime
526 '
527
528 test_expect_success 'test sparse status with untracked cache' '
529 : >../trace.output &&
530 - avoid_racy &&
530 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
531 git status --porcelain >../status.actual &&
532 iuc status --porcelain >../status.iuc &&
@@ -570,7 +569,6 @@ EOF
569 '
570
571 test_expect_success 'test sparse status again with untracked cache' '
573 - avoid_racy &&
572 : >../trace.output &&
573 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
574 git status --porcelain >../status.actual &&
@@ -597,11 +595,11 @@ EOF
595 test_expect_success 'set up for test of subdir and sparse checkouts' '
596 mkdir done/sub &&
597 mkdir done/sub/sub &&
600 - echo "sub" > done/sub/sub/file
598 + echo "sub" > done/sub/sub/file &&
599 + test-tool chmtime =-120 done/sub/sub/file done/sub/sub done/sub done
600 '
601
602 test_expect_success 'test sparse status with untracked cache and subdir' '
604 - avoid_racy &&
603 : >../trace.output &&
604 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
605 git status --porcelain >../status.actual &&
@@ -651,7 +649,6 @@ EOF
649 '
650
651 test_expect_success 'test sparse status again with untracked cache and subdir' '
654 - avoid_racy &&
652 : >../trace.output &&
653 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
654 git status --porcelain >../status.actual &&