Skip to content

Commit

Permalink
FunctionalTests: categorize tests using C# maintenance
Browse files Browse the repository at this point in the history
The 'git maintenance run' version of these steps behave slightly
differently and are tested in the Git codebase.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Oct 7, 2020
1 parent c1f1926 commit d54887b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

namespace Scalar.FunctionalTests.Tests.EnlistmentPerFixture
{
Expand Down Expand Up @@ -56,11 +57,18 @@ public void RepackAllToOnePack()
this.Enlistment.RunVerb("pack-files", batchSize: 0);
this.GetPackSizes(out int packCount, out maxSize, out minSize, out totalSize);

// We should not have expired any packs, but created a new one with repack
packCount.ShouldEqual(afterPrefetchPackCount + 1, $"incorrect number of packs after repack step: {packCount}");
// On Linux (and soon, macOS) we only use `git maintenance run --task=incremental-repack`
// which uses a "second-largest pack" batch size instead of our selected batch size.
// This part of the test will fail, but the rest is sound.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// We should not have expired any packs, but created a new one with repack
packCount.ShouldEqual(afterPrefetchPackCount + 1, $"incorrect number of packs after repack step: {packCount}");
}
}

[TestCase, Order(2)]
[Category(Categories.WindowsOnly)]
public void ExpireAllButOneAndKeep()
{
string prefetchPack = Directory.GetFiles(this.PackRoot, "prefetch-*.pack")
Expand Down
28 changes: 21 additions & 7 deletions Scalar.FunctionalTests/Tests/GitRepoPerFixture/RunVerbTests.cs
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace Scalar.FunctionalTests.Tests.GitRepoPerFixture
Expand Down Expand Up @@ -60,15 +61,28 @@ public void PackfileMaintenanceStep()
this.GetPackSizes(out int countAfterStep, out maxSize, out minSize, out totalSize);
minSize.ShouldNotEqual(0, "min size means empty pack-file?");

countAfterStep.ShouldEqual(countAfterRepack + 1, nameof(countAfterStep));
// The new batch logic in Git depends on the number of pack-files
// trying to pack everything except the biggest pack-file. If
// there are only two packs, then no work is done.
int expectAfterRerun;
if (countAfterRepack == 2)
{
countAfterStep.ShouldEqual(countAfterRepack, nameof(countAfterStep));
expectAfterRerun = countAfterRepack;
}
else
{
countAfterStep.ShouldEqual(countAfterRepack + 1, nameof(countAfterStep));
expectAfterRerun = 1;
}

this.Enlistment
.RunVerb("pack-files", batchSize: totalSize - minSize + 1)
.ShouldNotContain(false, "Skipping pack maintenance due to no .keep file.");

this.GetPackSizes(out int countAfterStep2, out maxSize, out minSize, out totalSize);
minSize.ShouldNotEqual(0, "min size means empty pack-file?");
countAfterStep2.ShouldEqual(1, nameof(countAfterStep2));
countAfterStep2.ShouldEqual(expectAfterRerun, nameof(countAfterStep2));
}

[TestCase]
Expand Down Expand Up @@ -104,8 +118,8 @@ public void FetchStep()
string refsRoot = Path.Combine(this.Enlistment.RepoRoot, ".git", "refs");
string refsHeads = Path.Combine(refsRoot, "heads");
string refsRemotesOrigin = Path.Combine(refsRoot, "remotes", "origin");
string refsHidden = Path.Combine(refsRoot, "scalar", "hidden");
string refsHiddenOriginFake = Path.Combine(refsHidden, "origin", "fake");
string refsPrefetch = Path.Combine(refsRoot, "prefetch");
string refsPrefetchOriginFake = Path.Combine(refsPrefetch, "origin", "fake");
string packedRefs = Path.Combine(this.Enlistment.RepoRoot, ".git", "packed-refs");

// Removing refs makes the next fetch need to download a new pack
Expand All @@ -124,20 +138,20 @@ public void FetchStep()

countAfterFetch.ShouldEqual(1, "fetch should download one pack");

this.fileSystem.DirectoryExists(refsHidden).ShouldBeTrue("background fetch should have created refs/scalar/hidden/*");
this.fileSystem.DirectoryExists(refsPrefetch).ShouldBeTrue("background fetch should have created refs/prefetch/*");
this.fileSystem.DirectoryExists(refsHeads).ShouldBeFalse("background fetch should not have created refs/heads/*");
this.fileSystem.DirectoryExists(refsRemotesOrigin).ShouldBeFalse("background fetch should not have created refs/remotes/origin/*");

// This is the SHA-1 for the main branch
string sha1 = Settings.Default.CommitId;
this.fileSystem.WriteAllText(refsHiddenOriginFake, sha1);
this.fileSystem.WriteAllText(refsPrefetchOriginFake, sha1);

this.Enlistment.RunVerb("fetch");

this.fileSystem.DirectoryExists(refsHeads).ShouldBeFalse("background fetch should not have created refs/heads/*");
this.fileSystem.DirectoryExists(refsRemotesOrigin).ShouldBeFalse("background fetch should not have created refs/remotes/origin/*");

this.fileSystem.FileExists(refsHiddenOriginFake).ShouldBeFalse("background fetch should clear deleted refs from refs/scalar/hidden");
this.fileSystem.FileExists(refsPrefetchOriginFake).ShouldBeFalse("background fetch should clear deleted refs from refs/prefetch");

this.GetPackSizes(out int countAfterFetch2, out _, out _, out _);
countAfterFetch2.ShouldEqual(1, "sceond fetch should not download a pack");
Expand Down

0 comments on commit d54887b

Please sign in to comment.