From 6f00c207c062c70a1d1fae45104beb6bb5429ad1 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 4 Oct 2018 11:10:26 -0400 Subject: [PATCH 1/2] SecondCloneSucceedsWithMissingTrees: Attempt 2 The previous approach to this test relied on deleting packfiles from the shared object cache. That failed on Windows because the .idx files have restrictive permissions that cause the delete to fail. Instead, use the loose object downloads to hydrate the commit and root tree for the WellKnownBranch and then do a clone pointing at that branch. This should trigger the failure case. --- .../MultiEnlistmentTests/SharedCacheTests.cs | 19 +++++++++++++++++++ .../TestsWithMultiEnlistment.cs | 11 +++++++++-- .../Tools/GVFSFunctionalTestEnlistment.cs | 8 ++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs index 7ec39205a1..f4026dccc1 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs @@ -268,6 +268,25 @@ public void MountUsesNewLocalCacheKeyWhenLocalCacheDeleted() this.AlternatesFileShouldHaveGitObjectsRoot(enlistment); } + [TestCase] + public void SecondCloneSucceedsWithMissingTrees() + { + string newCachePath = Path.Combine(this.localCacheParentPath, ".customGvfsCache2"); + GVFSFunctionalTestEnlistment enlistment1 = this.CreateNewEnlistment(localCacheRoot: newCachePath, skipPrefetch: true); + File.ReadAllText(Path.Combine(enlistment1.RepoRoot, WellKnownFile)); + this.AlternatesFileShouldHaveGitObjectsRoot(enlistment1); + + // This Git command loads the commit and root tree for WellKnownCommitSha, + // but does not download any more reachable objects. + string command = "cat-file -p origin/" + WellKnownBranch + "^{tree}"; + ProcessResult result = GitHelpers.InvokeGitAgainstGVFSRepo(enlistment1.RepoRoot, command); + result.ExitCode.ShouldEqual(0, $"git {command} failed with error: " + result.Errors); + + // If we did not properly check the failed checkout at this step, then clone will fail during checkout. + GVFSFunctionalTestEnlistment enlistment2 = this.CreateNewEnlistment(localCacheRoot: newCachePath, branch: WellKnownBranch, skipPrefetch: true); + File.ReadAllText(Path.Combine(enlistment2.RepoRoot, WellKnownFile)); + } + // Override OnTearDownEnlistmentsDeleted rathern than using [TearDown] as the enlistments need to be unmounted before // localCacheParentPath can be deleted (as the SQLite blob sizes database cannot be deleted while GVFS is mounted) protected override void OnTearDownEnlistmentsDeleted() diff --git a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/TestsWithMultiEnlistment.cs b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/TestsWithMultiEnlistment.cs index f0afd93995..3c9a353272 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/TestsWithMultiEnlistment.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/TestsWithMultiEnlistment.cs @@ -28,9 +28,16 @@ protected virtual void OnTearDownEnlistmentsDeleted() { } - protected GVFSFunctionalTestEnlistment CreateNewEnlistment(string localCacheRoot = null, string branch = null) + protected GVFSFunctionalTestEnlistment CreateNewEnlistment( + string localCacheRoot = null, + string branch = null, + bool skipPrefetch = false) { - GVFSFunctionalTestEnlistment output = GVFSFunctionalTestEnlistment.CloneAndMount(GVFSTestConfig.PathToGVFS, branch, localCacheRoot); + GVFSFunctionalTestEnlistment output = GVFSFunctionalTestEnlistment.CloneAndMount( + GVFSTestConfig.PathToGVFS, + branch, + localCacheRoot, + skipPrefetch); this.enlistmentsToDelete.Add(output); return output; } diff --git a/GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs b/GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs index 427fef7b28..eb6ea827cb 100644 --- a/GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs +++ b/GVFS/GVFS.FunctionalTests/Tools/GVFSFunctionalTestEnlistment.cs @@ -89,10 +89,14 @@ public static GVFSFunctionalTestEnlistment CloneAndMountWithPerRepoCache(string return CloneAndMount(pathToGvfs, enlistmentRoot, null, localCache, skipPrefetch); } - public static GVFSFunctionalTestEnlistment CloneAndMount(string pathToGvfs, string commitish = null, string localCacheRoot = null) + public static GVFSFunctionalTestEnlistment CloneAndMount( + string pathToGvfs, + string commitish = null, + string localCacheRoot = null, + bool skipPrefetch = false) { string enlistmentRoot = GVFSFunctionalTestEnlistment.GetUniqueEnlistmentRoot(); - return CloneAndMount(pathToGvfs, enlistmentRoot, commitish, localCacheRoot); + return CloneAndMount(pathToGvfs, enlistmentRoot, commitish, localCacheRoot, skipPrefetch); } public static GVFSFunctionalTestEnlistment CloneAndMountEnlistmentWithSpacesInPath(string pathToGvfs, string commitish = null) From 43287ecf8d7f821a2e286fc6c67a2e1eaed2c0c2 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 4 Oct 2018 13:41:36 -0400 Subject: [PATCH 2/2] SharedCacheTests: Update WellKnownCommitSha This doesn't match, as we expect it to! --- .../Tests/MultiEnlistmentTests/SharedCacheTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs index f4026dccc1..c7b3072f2a 100644 --- a/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs +++ b/GVFS/GVFS.FunctionalTests/Tests/MultiEnlistmentTests/SharedCacheTests.cs @@ -21,7 +21,7 @@ public class SharedCacheTests : TestsWithMultiEnlistment // This branch and commit sha should point to the same place. private const string WellKnownBranch = "FunctionalTests/20170602"; - private const string WellKnownCommitSha = "79dc4233df4d9a7e053662bff95df498f640022e"; + private const string WellKnownCommitSha = "42eb6632beffae26893a3d6e1a9f48d652327c6f"; private string localCachePath; private string localCacheParentPath;