Skip to content

Commit 3294ca6

Browse files
jeffhostetlergitster
authored andcommitted
t7527: improve implicit shutdown testing in fsmonitor--daemon
Refactor the tests that exercise implicit shutdown cases to make them more robust and less racy. The fsmonitor--daemon will implicitly shutdown in a variety of situations, such as when the ".git" directory is deleted or renamed. The existing tests would delete or rename the directory, sleep for one second, and then check the status of the daemon. This is racy, since the client/status command has no way to sync with the daemon. This was noticed occasionally on very slow CI build machines where it would cause a random test to fail. Replace the simple sleep with a sleep-and-retry loop. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53fcfbc commit 3294ca6

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

t/t7527-builtin-fsmonitor.sh

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,36 @@ test_expect_success 'implicit daemon start' '
124124
test_must_fail git -C test_implicit fsmonitor--daemon status
125125
'
126126

127+
# Verify that the daemon has shutdown. Spin a few seconds to
128+
# make the test a little more robust during CI testing.
129+
#
130+
# We're looking for an implicit shutdown, such as when we delete or
131+
# rename the ".git" directory. Our delete/rename will cause a file
132+
# system event that the daemon will see and the daemon will
133+
# auto-shutdown as soon as it sees it. But this is racy with our `git
134+
# fsmonitor--daemon status` commands (and we cannot use a cookie file
135+
# here to help us). So spin a little and give the daemon a chance to
136+
# see the event. (This is primarily for underpowered CI build/test
137+
# machines (where it might take a moment to wake and reschedule the
138+
# daemon process) to avoid false alarms during test runs.)
139+
#
140+
IMPLICIT_TIMEOUT=5
141+
142+
verify_implicit_shutdown () {
143+
r=$1 &&
144+
145+
k=0 &&
146+
while test "$k" -lt $IMPLICIT_TIMEOUT
147+
do
148+
git -C $r fsmonitor--daemon status || return 0
149+
150+
sleep 1
151+
k=$(( $k + 1 ))
152+
done &&
153+
154+
return 1
155+
}
156+
127157
test_expect_success 'implicit daemon stop (delete .git)' '
128158
test_when_finished "stop_daemon_delete_repo test_implicit_1" &&
129159
@@ -142,10 +172,9 @@ test_expect_success 'implicit daemon stop (delete .git)' '
142172
# This would make the test result dependent upon whether we
143173
# were using fsmonitor on our development worktree.
144174
#
145-
sleep 1 &&
146175
mkdir test_implicit_1/.git &&
147176
148-
test_must_fail git -C test_implicit_1 fsmonitor--daemon status
177+
verify_implicit_shutdown test_implicit_1
149178
'
150179

151180
test_expect_success 'implicit daemon stop (rename .git)' '
@@ -160,10 +189,9 @@ test_expect_success 'implicit daemon stop (rename .git)' '
160189
161190
# See [1] above.
162191
#
163-
sleep 1 &&
164192
mkdir test_implicit_2/.git &&
165193
166-
test_must_fail git -C test_implicit_2 fsmonitor--daemon status
194+
verify_implicit_shutdown test_implicit_2
167195
'
168196

169197
# File systems on Windows may or may not have shortnames.
@@ -194,13 +222,11 @@ test_expect_success MINGW,SHORTNAMES 'implicit daemon stop (rename GIT~1)' '
194222
#
195223
mv test_implicit_1s/GIT~1 test_implicit_1s/.gitxyz &&
196224
197-
sleep 1 &&
198-
# put it back so that our status will not crawl out to our
199-
# parent directory.
225+
# See [1] above.
200226
# this moves {.gitxyz, GITXYZ~1} to {.git, GIT~1}.
201227
mv test_implicit_1s/.gitxyz test_implicit_1s/.git &&
202228
203-
test_must_fail git -C test_implicit_1s fsmonitor--daemon status
229+
verify_implicit_shutdown test_implicit_1s
204230
'
205231

206232
# Here we first create a file with LONGNAME of "GIT~1" before
@@ -223,12 +249,10 @@ test_expect_success MINGW,SHORTNAMES 'implicit daemon stop (rename GIT~2)' '
223249
#
224250
mv test_implicit_1s2/GIT~2 test_implicit_1s2/.gitxyz &&
225251
226-
sleep 1 &&
227-
# put it back so that our status will not crawl out to our
228-
# parent directory.
252+
# See [1] above.
229253
mv test_implicit_1s2/.gitxyz test_implicit_1s2/.git &&
230254
231-
test_must_fail git -C test_implicit_1s2 fsmonitor--daemon status
255+
verify_implicit_shutdown test_implicit_1s2
232256
'
233257

234258
test_expect_success 'cannot start multiple daemons' '
@@ -905,9 +929,11 @@ test_expect_success CASE_INSENSITIVE_FS 'case insensitive+preserving' '
905929
# Rename .git using an alternate spelling to verify that that
906930
# daemon detects it and automatically shuts down.
907931
mv test_insensitive/.GIT test_insensitive/.FOO &&
908-
sleep 1 &&
932+
933+
# See [1] above.
909934
mv test_insensitive/.FOO test_insensitive/.git &&
910-
test_must_fail git -C test_insensitive fsmonitor--daemon status &&
935+
936+
verify_implicit_shutdown test_insensitive &&
911937
912938
# Verify that events were reported using on-disk spellings of the
913939
# directories and files that we touched. We may or may not get a

0 commit comments

Comments
 (0)