From 46fad7855bd5dc991008b7852f424152d32c7b82 Mon Sep 17 00:00:00 2001 From: Sami Hiltunen Date: Tue, 26 Apr 2022 12:28:30 +0300 Subject: Fix flaky ObjectReader test TestCache_ObjectReader/uncacheable is asserting that the object reader is closed after the context provided in the constructor is canceled. The clean up happens in a goroutine that listens for context cancellation and is thus not synchronizable by the calling code. It would be better if the clean up calls were explicit and synchronous so the calling code could synchronize if it wanted to. That's a bigger change though, so for now, let's use require.Eventually in the test to fix the flakiness by retrying the condition until it succeeds. --- internal/git/catfile/cache_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/git/catfile/cache_test.go b/internal/git/catfile/cache_test.go index b90124ec8..b253869d9 100644 --- a/internal/git/catfile/cache_test.go +++ b/internal/git/catfile/cache_test.go @@ -218,7 +218,9 @@ func TestCache_ObjectReader(t *testing.T) { } require.Empty(t, output) - require.True(t, reader.isClosed()) + // The clean up happens in a goroutine on context cancellation. require.Eventually + // is used to here to avoid the flakiness. + require.Eventually(t, reader.isClosed, 5*time.Second, time.Millisecond) require.Empty(t, keys(t, &cache.objectReaders)) }) -- cgit v1.2.3