forked from microsoft/VFSForGit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefetchVerbTests.cs
More file actions
152 lines (132 loc) · 6.34 KB
/
PrefetchVerbTests.cs
File metadata and controls
152 lines (132 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using GVFS.FunctionalTests.FileSystemRunners;
using GVFS.FunctionalTests.Should;
using GVFS.FunctionalTests.Tools;
using GVFS.Tests.Should;
using NUnit.Framework;
using System.IO;
using System.Threading;
namespace GVFS.FunctionalTests.Tests.EnlistmentPerFixture
{
[TestFixture]
[NonParallelizable]
public class PrefetchVerbTests : TestsWithEnlistmentPerFixture
{
private const string PrefetchCommitsAndTreesLock = "prefetch-commits-trees.lock";
private FileSystemRunner fileSystem;
public PrefetchVerbTests()
{
this.fileSystem = new SystemIORunner();
}
[TestCase, Order(1)]
public void PrefetchAllMustBeExplicit()
{
this.Enlistment.Prefetch(string.Empty, failOnError: false).ShouldContain("Did you mean to fetch all blobs?");
}
[TestCase, Order(2)]
public void PrefetchSpecificFiles()
{
this.ExpectBlobCount(this.Enlistment.Prefetch($"--files {Path.Combine("GVFS", "GVFS", "Program.cs")}"), 1);
this.ExpectBlobCount(this.Enlistment.Prefetch($"--files {Path.Combine("GVFS", "GVFS", "Program.cs")};{Path.Combine("GVFS", "GVFS.FunctionalTests", "GVFS.FunctionalTests.csproj")}"), 2);
}
[TestCase, Order(3)]
public void PrefetchByFileExtension()
{
this.ExpectBlobCount(this.Enlistment.Prefetch("--files *.cs"), 199);
this.ExpectBlobCount(this.Enlistment.Prefetch("--files *.cs;*.csproj"), 208);
}
[TestCase, Order(4)]
public void PrefetchByFileExtensionWithHydrate()
{
int expectedCount = 3;
string output = this.Enlistment.Prefetch("--files *.md --hydrate");
this.ExpectBlobCount(output, expectedCount);
output.ShouldContain("Hydrated files: " + expectedCount);
}
[TestCase, Order(5)]
public void PrefetchByFilesWithHydrateWhoseObjectsAreAlreadyDownloaded()
{
int expectedCount = 2;
string output = this.Enlistment.Prefetch(
$"--files {Path.Combine("GVFS", "GVFS", "Program.cs")};{Path.Combine("GVFS", "GVFS.FunctionalTests", "GVFS.FunctionalTests.csproj")} --hydrate");
this.ExpectBlobCount(output, expectedCount);
output.ShouldContain("Hydrated files: " + expectedCount);
output.ShouldContain("Downloaded: 0");
}
[TestCase, Order(6)]
public void PrefetchFolders()
{
this.ExpectBlobCount(this.Enlistment.Prefetch($"--folders {Path.Combine("GVFS", "GVFS")}"), 17);
this.ExpectBlobCount(this.Enlistment.Prefetch($"--folders {Path.Combine("GVFS", "GVFS")};{Path.Combine("GVFS", "GVFS.FunctionalTests")}"), 65);
}
[TestCase, Order(7)]
public void PrefetchIsAllowedToDoNothing()
{
this.ExpectBlobCount(this.Enlistment.Prefetch("--files nonexistent.txt"), 0);
this.ExpectBlobCount(this.Enlistment.Prefetch("--folders nonexistent_folder"), 0);
}
[TestCase, Order(8)]
public void PrefetchFolderListFromFile()
{
string tempFilePath = Path.Combine(Path.GetTempPath(), "temp.file");
File.WriteAllLines(
tempFilePath,
new[]
{
"# A comment",
" ",
"gvfs/",
"gvfs/gvfs",
"gvfs/"
});
this.ExpectBlobCount(this.Enlistment.Prefetch("--folders-list " + tempFilePath), 279);
File.Delete(tempFilePath);
}
[TestCase, Order(9)]
public void PrefetchAll()
{
this.ExpectBlobCount(this.Enlistment.Prefetch("--files *"), 494);
this.ExpectBlobCount(this.Enlistment.Prefetch("--folders /"), 494);
this.ExpectBlobCount(this.Enlistment.Prefetch($"--folders {Path.DirectorySeparatorChar}"), 494);
}
// TODO(Mac): Handle that lock files are not deleted on Mac, they are simply unlocked
[TestCase, Order(10)]
[Category(Categories.MacTODO.M4)]
public void PrefetchCleansUpStalePrefetchLock()
{
this.Enlistment.Prefetch("--commits");
this.PostFetchJobShouldComplete();
string prefetchCommitsLockFile = Path.Combine(this.Enlistment.GetObjectRoot(this.fileSystem), "pack", PrefetchCommitsAndTreesLock);
prefetchCommitsLockFile.ShouldNotExistOnDisk(this.fileSystem);
this.fileSystem.WriteAllText(prefetchCommitsLockFile, this.Enlistment.EnlistmentRoot);
prefetchCommitsLockFile.ShouldBeAFile(this.fileSystem);
this.Enlistment.Prefetch("--commits");
this.PostFetchJobShouldComplete();
prefetchCommitsLockFile.ShouldNotExistOnDisk(this.fileSystem);
}
private void ExpectBlobCount(string output, int expectedCount)
{
output.ShouldContain("Matched blobs: " + expectedCount);
}
private void PostFetchJobShouldComplete()
{
string objectDir = this.Enlistment.GetObjectRoot(this.fileSystem);
string postFetchLock = Path.Combine(objectDir, "post-fetch.lock");
// Wait first, to hopefully ensure the background thread has
// started before we check for the lock file.
do
{
Thread.Sleep(500);
}
while (this.fileSystem.FileExists(postFetchLock));
ProcessResult midxResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "multi-pack-index verify --object-dir=\"" + objectDir + "\"");
midxResult.ExitCode.ShouldEqual(0);
// A commit graph is not always generated, but if it is, then we want to ensure it is in a good state
if (this.fileSystem.FileExists(Path.Combine(objectDir, "info", "commit-graph")))
{
ProcessResult graphResult = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "commit-graph read --object-dir=\"" + objectDir + "\"");
graphResult.ExitCode.ShouldEqual(0);
graphResult.Output.ShouldContain("43475048"); // Header from commit-graph file.
}
}
}
}