diff mbox series

[v2,1/3] t7519: avoid file to index mtime race for untracked cache

Message ID 9421b71540d1f1764db6931d0781576d8a710866.1645809015.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series Empty untracked cache performance issue | expand

Commit Message

Tao Klerks Feb. 25, 2022, 5:10 p.m. UTC
From: Tao Klerks <tao@klerks.biz>

In t7519 there is a test that writes files to disk, and immediately
writes the untracked index. Because of mtime-comparison logic that
uses a 1-second resolution, this means the cached entries are not
trusted/used under some circumstances
(see read-cache.c#is_racy_stat()).

Untracked cache tests in t7063 use a 1-second delay to avoid this
issue, but we don't want to introduce arbitrary slowdowns, so instead
use test-tool chmtime to backdate the files slightly.

This change doesn't actually affect the outcome of the test, but does
enhance its validity, and becomes relevant after later changes.

Signed-off-by: Tao Klerks <tao@klerks.biz>
---
 t/t7519-status-fsmonitor.sh | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Junio C Hamano Feb. 25, 2022, 7:07 p.m. UTC | #1
"Tao Klerks via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Tao Klerks <tao@klerks.biz>
>
> In t7519 there is a test that writes files to disk, and immediately
> writes the untracked index. Because of mtime-comparison logic that

"untracked cache", I think.

> uses a 1-second resolution, this means the cached entries are not
> trusted/used under some circumstances
> (see read-cache.c#is_racy_stat()).
>
> Untracked cache tests in t7063 use a 1-second delay to avoid this
> issue, but we don't want to introduce arbitrary slowdowns, so instead
> use test-tool chmtime to backdate the files slightly.

Good approach.  Perhaps fixing 7063 can be marked as #leftoverbit?

> This change doesn't actually affect the outcome of the test, but does
> enhance its validity, and becomes relevant after later changes.
>
> Signed-off-by: Tao Klerks <tao@klerks.biz>
> ---
>  t/t7519-status-fsmonitor.sh | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh
> index a6308acf006..3f984136ea9 100755
> --- a/t/t7519-status-fsmonitor.sh
> +++ b/t/t7519-status-fsmonitor.sh
> @@ -324,13 +324,19 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
>  		cd dot-git &&
>  		mkdir -p .git/hooks &&
>  		: >tracked &&
> +		test-tool chmtime =-60 tracked &&
>  		: >modified &&
> +		test-tool chmtime =-60 modified &&
>  		mkdir dir1 &&
>  		: >dir1/tracked &&
> +		test-tool chmtime =-60 dir1/tracked &&
>  		: >dir1/modified &&
> +		test-tool chmtime =-60 dir1/modified &&
>  		mkdir dir2 &&
>  		: >dir2/tracked &&
> +		test-tool chmtime =-60 dir2/tracked &&
>  		: >dir2/modified &&
> +		test-tool chmtime =-60 dir2/modified &&
>  		write_integration_script &&
>  		git config core.fsmonitor .git/hooks/fsmonitor-test &&
>  		git update-index --untracked-cache &&
Tao Klerks Feb. 27, 2022, 10:12 p.m. UTC | #2
On Fri, Feb 25, 2022 at 8:07 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Tao Klerks via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > In t7519 there is a test that writes files to disk, and immediately
> > writes the untracked index. Because of mtime-comparison logic that
>
> "untracked cache", I think.
>

Yep, fixed, thx.

> > uses a 1-second resolution, this means the cached entries are not
> > trusted/used under some circumstances
> > (see read-cache.c#is_racy_stat()).
> >
> > Untracked cache tests in t7063 use a 1-second delay to avoid this
> > issue, but we don't want to introduce arbitrary slowdowns, so instead
> > use test-tool chmtime to backdate the files slightly.
>
> Good approach.  Perhaps fixing 7063 can be marked as #leftoverbit?
>

Sure. Updated the commit msg.

I also started another thread with what that looks like - it's not very pretty
in the end because of Windows compatibility issues, and still incomplete
because (as far as I can tell) the sleep is used for a couple of different
purposes, and only one of them lends itself to chmtime manipulation.
diff mbox series

Patch

diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh
index a6308acf006..3f984136ea9 100755
--- a/t/t7519-status-fsmonitor.sh
+++ b/t/t7519-status-fsmonitor.sh
@@ -324,13 +324,19 @@  test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
 		cd dot-git &&
 		mkdir -p .git/hooks &&
 		: >tracked &&
+		test-tool chmtime =-60 tracked &&
 		: >modified &&
+		test-tool chmtime =-60 modified &&
 		mkdir dir1 &&
 		: >dir1/tracked &&
+		test-tool chmtime =-60 dir1/tracked &&
 		: >dir1/modified &&
+		test-tool chmtime =-60 dir1/modified &&
 		mkdir dir2 &&
 		: >dir2/tracked &&
+		test-tool chmtime =-60 dir2/tracked &&
 		: >dir2/modified &&
+		test-tool chmtime =-60 dir2/modified &&
 		write_integration_script &&
 		git config core.fsmonitor .git/hooks/fsmonitor-test &&
 		git update-index --untracked-cache &&