Skip to content

Commit e51165f

Browse files
committed
test-lib: clear watchman watches at test completion
The fsmonitor feature allows an external tool such as watchman to monitor the working directory. The direct test t7619-status-fsmonitor.sh provides some coverage, but it would be better to run the entire test suite with watchman enabled. This would provide more confidence that the feature is working as intended. When running the test suite in parallel with 'prove -j <N>', many repos are created and deleted in parallel. When GIT_TEST_FSMONITOR points to t/t7519/fsmonitor-watchman, this can lead to watchman tracking many different folders, overloading its watch queue. As a test script completes, we can tell watchman to stop watching the directories inside the TRASH_DIRECTORY. This is particularly important on Windows where watchman keeps an open handle on the directories it watches, preventing them from being deleted. There is currently a bug in watchman [1] where this handle still is not closed, but if that is updated then these tests can be run on Windows as well. [1] facebook/watchman#764 Signed-off-by: Derrick Stolee <[email protected]>
1 parent 215ec86 commit e51165f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

t/test-lib-functions.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,3 +1475,18 @@ test_set_port () {
14751475
port=$(($port + ${GIT_TEST_STRESS_JOB_NR:-0}))
14761476
eval $var=$port
14771477
}
1478+
1479+
test_clear_watchman () {
1480+
if test -n "$GIT_TEST_FSMONITOR"
1481+
then
1482+
watchman watch-list |
1483+
grep "$TRASH_DIRECTORY" |
1484+
sed "s/\",//g" |
1485+
sed "s/\"//g" >repo-list
1486+
1487+
while read repo
1488+
do
1489+
watchman watch-del "$repo"
1490+
done <repo-list
1491+
fi
1492+
}

t/test-lib.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,10 @@ test_atexit_handler () {
10811081
test_done () {
10821082
GIT_EXIT_OK=t
10831083

1084+
# If watchman is being used with GIT_TEST_FSMONITOR, then
1085+
# clear all watches on directories inside the TRASH_DIRECTORY.
1086+
test_clear_watchman
1087+
10841088
# Run the atexit commands _before_ the trash directory is
10851089
# removed, so the commands can access pidfiles and socket files.
10861090
test_atexit_handler

0 commit comments

Comments
 (0)