Skip to content

Commit

Permalink
GitStatusCache: fix race condition in test setup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jamill committed Aug 15, 2018
1 parent 8431ab2 commit 5639431
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions GVFS/GVFS.FunctionalTests/Tests/GitCommands/StatusTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -110,6 +112,18 @@ private void RepositoryIgnoreTestSetup()
this.ValidateGitCommand("status");
}

/// <summary>
/// Wait for an up-to-date status cache file to exist on disk.
/// </summary>
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");
Expand Down

0 comments on commit 5639431

Please sign in to comment.