Skip to content

Commit 9ba83eb

Browse files
TaoKgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 090a308 commit 9ba83eb

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

t/t7063-status-untracked-cache.sh

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ test_expect_success 'setup' '
9090
cd worktree &&
9191
mkdir done dtwo dthree &&
9292
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 . &&
9396
git add one two done/one &&
9497
: >.git/info/exclude &&
9598
git update-index --untracked-cache &&
@@ -142,7 +145,6 @@ two
142145
EOF
143146

144147
test_expect_success 'status first time (empty cache)' '
145-
avoid_racy &&
146148
: >../trace.output &&
147149
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
148150
git status --porcelain >../actual &&
@@ -166,7 +168,6 @@ test_expect_success 'untracked cache after first status' '
166168
'
167169

168170
test_expect_success 'status second time (fully populated cache)' '
169-
avoid_racy &&
170171
: >../trace.output &&
171172
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
172173
git status --porcelain >../actual &&
@@ -190,8 +191,8 @@ test_expect_success 'untracked cache after second status' '
190191
'
191192

192193
test_expect_success 'modify in root directory, one dir invalidation' '
193-
avoid_racy &&
194194
: >four &&
195+
test-tool chmtime =-240 four &&
195196
: >../trace.output &&
196197
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
197198
git status --porcelain >../actual &&
@@ -241,7 +242,6 @@ EOF
241242
'
242243

243244
test_expect_success 'new .gitignore invalidates recursively' '
244-
avoid_racy &&
245245
echo four >.gitignore &&
246246
: >../trace.output &&
247247
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
@@ -292,7 +292,6 @@ EOF
292292
'
293293

294294
test_expect_success 'new info/exclude invalidates everything' '
295-
avoid_racy &&
296295
echo three >>.git/info/exclude &&
297296
: >../trace.output &&
298297
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
@@ -520,14 +519,14 @@ test_expect_success 'create/modify files, some of which are gitignored' '
520519
echo three >done/three && # three is gitignored
521520
echo four >done/four && # four is gitignored at a higher level
522521
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 . &&
525525
sync_mtime
526526
'
527527

528528
test_expect_success 'test sparse status with untracked cache' '
529529
: >../trace.output &&
530-
avoid_racy &&
531530
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
532531
git status --porcelain >../status.actual &&
533532
iuc status --porcelain >../status.iuc &&
@@ -570,7 +569,6 @@ EOF
570569
'
571570

572571
test_expect_success 'test sparse status again with untracked cache' '
573-
avoid_racy &&
574572
: >../trace.output &&
575573
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
576574
git status --porcelain >../status.actual &&
@@ -597,11 +595,11 @@ EOF
597595
test_expect_success 'set up for test of subdir and sparse checkouts' '
598596
mkdir done/sub &&
599597
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
601600
'
602601

603602
test_expect_success 'test sparse status with untracked cache and subdir' '
604-
avoid_racy &&
605603
: >../trace.output &&
606604
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
607605
git status --porcelain >../status.actual &&
@@ -651,7 +649,6 @@ EOF
651649
'
652650

653651
test_expect_success 'test sparse status again with untracked cache and subdir' '
654-
avoid_racy &&
655652
: >../trace.output &&
656653
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
657654
git status --porcelain >../status.actual &&

0 commit comments

Comments
 (0)