From fcf6e52d14bc96a5afd6f040b241af1e54be64c3 Mon Sep 17 00:00:00 2001 From: Jameson Miller Date: Wed, 15 Aug 2018 12:42:40 -0400 Subject: [PATCH] GitStatusCache: fix race condition in test setup This is to fix an issue that happened (intermittently) in the functional tests. There is a race condition where the test is attempting to delete the status cache file, but the status cache might not have been generated for the test repository. To fix this, the test setup will wait for the initial status cache to be generated, so it can proceed from a known state. (cherry picked from commit 97975e4396893a9b44544bfe8a098196008e73b8) --- .../Tests/GitCommands/StatusTests.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/StatusTests.cs b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/StatusTests.cs index a66d691c9..9865431c3 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/GitCommands/StatusTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/GitCommands/StatusTests.cs @@ -98,6 +98,8 @@ public void ModifyingHeadRefInvalidatesCache() private void RepositoryIgnoreTestSetup() { + this.WaitForUpToDateStatusCache(); + string statusCachePath = Path.Combine(this.Enlistment.DotGVFSRoot, "GitStatusCache", "GitStatusCache.dat"); File.Delete(statusCachePath); @@ -110,6 +112,18 @@ private void RepositoryIgnoreTestSetup() this.ValidateGitCommand("status"); } + /// + /// Wait for an up-to-date status cache file to exist on disk. + /// + private void WaitForUpToDateStatusCache() + { + // Run "git status" for the side effect that it will delete any stale status cache file. + this.ValidateGitCommand("status"); + + // Wait for a new status cache to be generated. + this.WaitForStatusCacheToBeGenerated(waitForNewFile: false); + } + private void WaitForStatusCacheToBeGenerated(bool waitForNewFile = true) { string statusCachePath = Path.Combine(this.Enlistment.DotGVFSRoot, "GitStatusCache", "GitStatusCache.dat");