10
test_done
11
fi
12
13
+# Verify that the filesystem delivers events to the daemon.
14
+# On some configurations (e.g., overlayfs with older kernels),
15
+# inotify watches succeed but events are never delivered. The
16
+# cookie wait will time out and the daemon logs a trace message.
17
+#
18
+# Use "timeout" (if available) to guard each step against hangs.
19
+maybe_timeout () {
20
+ if type timeout >/dev/null 2>&1
21
+ then
22
+ timeout "$@"
23
+ else
24
+ shift
25
+ "$@"
26
+ fi
27
+}
28
+verify_fsmonitor_works () {
29
+ git init test_fsmonitor_smoke || return 1
30
+
31
+ GIT_TRACE_FSMONITOR="$PWD/smoke.trace" &&
32
+ export GIT_TRACE_FSMONITOR &&
33
+ maybe_timeout 30 \
34
+ git -C test_fsmonitor_smoke fsmonitor--daemon start \
35
+ --start-timeout=10
36
+ ret=$?
37
+ unset GIT_TRACE_FSMONITOR
38
+ if test $ret -ne 0
39
+ then
40
+ rm -rf test_fsmonitor_smoke smoke.trace
41
+ return 1
42
+ fi
43
+
44
+ maybe_timeout 10 \
45
+ test-tool -C test_fsmonitor_smoke fsmonitor-client query \
46
+ --token 0 >/dev/null 2>&1
47
+ maybe_timeout 5 \
48
+ git -C test_fsmonitor_smoke fsmonitor--daemon stop 2>/dev/null
49
+ ! grep -q "cookie_wait timed out" "$PWD/smoke.trace" 2>/dev/null
50
+ ret=$?
51
+ rm -rf test_fsmonitor_smoke smoke.trace
52
+ return $ret
53
+}
54
+
55
+if ! verify_fsmonitor_works
56
+then
57
+ skip_all="filesystem does not deliver fsmonitor events (container/overlayfs?)"
58
+ test_done
59
+fi
60
+
61
stop_daemon_delete_repo () {
62
r=$1 &&
15
- test_might_fail git -C $r fsmonitor--daemon stop &&
63
+ { maybe_timeout 30 git -C $r fsmonitor--daemon stop 2>/dev/null || :; } &&
64
rm -rf $1
65
}
66
115
export GIT_TEST_FSMONITOR_TOKEN
116
fi &&
117
70
- git $r fsmonitor--daemon start &&
118
+ git $r fsmonitor--daemon start --start-timeout=10 &&
119
git $r fsmonitor--daemon status
120
)
121
}
568
grep "^event: dir1$" .git/trace
569
'
570
571
+test_expect_success 'rapid nested directory creation' '
572
+ test_when_finished "git fsmonitor--daemon stop; rm -rf rapid" &&
573
+
574
+ start_daemon --tf "$PWD/.git/trace" &&
575
+
576
+ # Rapidly create nested directories to exercise race conditions
577
+ # where directory watches may be added concurrently during
578
+ # event processing and recursive scanning.
579
+ for i in $(test_seq 1 20)
580
+ do
581
+ mkdir -p "rapid/nested/dir$i/subdir/deep" || return 1
582
+ done &&
583
+
584
+ # Give the daemon time to process all events
585
+ sleep 1 &&
586
+
587
+ test-tool fsmonitor-client query --token 0 &&
588
+
589
+ # Verify daemon is still running (did not crash)
590
+ git fsmonitor--daemon status
591
+'
592
+
593
# The next few test cases exercise the token-resync code. When filesystem
594
# drops events (because of filesystem velocity or because the daemon isn't
595
# polling fast enough), we need to discard the cached data (relative to the
980
start_git_in_background () {
981
git "$@" &
982
git_pid=$!
913
- git_pgid=$(ps -o pgid= -p $git_pid)
983
+ git_pgid=$(ps -o pgid= -p $git_pid 2>/dev/null ||
984
+ awk '{print $5}' /proc/$git_pid/stat 2>/dev/null) &&
985
+ git_pgid="${git_pgid## }" &&
986
+ git_pgid="${git_pgid%% }"
987
nr_tries_left=10
988
while true
989
do
994
fi
995
sleep 1
996
nr_tries_left=$(($nr_tries_left - 1))
924
- done >/dev/null 2>&1 &
997
+ done >/dev/null 2>&1 3>&- 4>&- 5>&- 6>&- 7>&- &
998
watchdog_pid=$!
999
wait $git_pid
1000
}
1001
1002
stop_git () {
930
- while kill -0 -- -$git_pgid
1003
+ test -n "$git_pgid" || return 0
1004
+ while kill -0 -- -$git_pgid 2>/dev/null
1005
do
932
- kill -- -$git_pgid
1006
+ kill -- -$git_pgid 2>/dev/null
1007
sleep 1
1008
done
1009
}
1018
1019
test_expect_success !MINGW "submodule implicitly starts daemon by pull" '
1020
test_atexit "stop_watchdog" &&
947
- test_when_finished "stop_git; rm -rf cloned super sub" &&
1021
+ test_when_finished "set +m; stop_git; rm -rf cloned super sub" &&
1022
1023
create_super super &&
1024
create_sub sub &&