Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit af8472a

Browse files
committed
Fix tests that rely on having a git zip around
Since we aren't embedding the zips in the dll anymore, tests that rely on them were trying to download things, and that causes timeouts. Embed the zips in the test assembly so they're available for the tests, and put them in place when starting up the test web server as well, so they can be served for downloading tests.
1 parent 72c1551 commit af8472a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+364
-84
lines changed

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,12 @@
280280
<Content Include="PlatformResources\windows\git.zip">
281281
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
282282
</Content>
283-
<EmbeddedResource Include="PlatformResources\mac\gitconfig" />
284-
<EmbeddedResource Include="PlatformResources\windows\gitconfig" />
283+
<EmbeddedResource Include="PlatformResources\mac\gitconfig">
284+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
285+
</EmbeddedResource>
286+
<EmbeddedResource Include="PlatformResources\windows\gitconfig">
287+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
288+
</EmbeddedResource>
285289
</ItemGroup>
286290
<ItemGroup>
287291
<EmbeddedResource Include="Resources\.gitattributes" />
@@ -296,6 +300,22 @@
296300
</ItemGroup>
297301
<ItemGroup>
298302
<None Include="packages.config" />
303+
<Content Include="PlatformResources\linux\git-lfs.zip">
304+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
305+
</Content>
306+
<Content Include="PlatformResources\linux\git-lfs.zip.md5" />
307+
<Content Include="PlatformResources\mac\git-lfs.zip.md5">
308+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
309+
</Content>
310+
<Content Include="PlatformResources\windows\git-lfs.zip.md5">
311+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
312+
</Content>
313+
<Content Include="PlatformResources\windows\git.zip.md5">
314+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
315+
</Content>
316+
<EmbeddedResource Include="PlatformResources\linux\gitconfig">
317+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
318+
</EmbeddedResource>
299319
</ItemGroup>
300320
<ItemGroup />
301321
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

src/GitHub.Api/Helpers/AssemblyResources.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public static NPath ToFile(ResourceType resourceType, string resource, NPath des
2424
var type = resourceType == ResourceType.Icon ? "IconsAndLogos"
2525
: resourceType == ResourceType.Platform ? "PlatformResources"
2626
: "Resources";
27-
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
27+
28+
var asm = Assembly.GetCallingAssembly();
29+
if (!asm.FullName.StartsWith("IntegrationTests"))
30+
asm = typeof(AssemblyResources).Assembly;
31+
var stream = asm.GetManifestResourceStream(
2832
String.Format("GitHub.Unity.{0}{1}.{2}", type, !string.IsNullOrEmpty(os) ? "." + os : os, resource));
2933
if (stream != null)
3034
return destinationPath.Combine(resource).WriteAllBytes(stream.ToByteArray());

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,29 @@ private GitInstallationState VerifyGitInstallation()
9595
}
9696
else
9797
Logger.Trace($"{installDetails.GitLfsExecutablePath} does not exist");
98+
99+
if (!state.GitZipExists)
100+
Logger.Trace($"{installDetails.GitZipPath} does not exist");
101+
if (!state.GitLfsZipExists)
102+
Logger.Trace($"{installDetails.GitLfsZipPath} does not exist");
98103
installationTask.UpdateProgress(10, 100);
99104
return state;
100105
}
101106

102107
private GitInstallationState GrabZipFromResources(GitInstallationState state)
103108
{
104109
if (!state.GitZipExists)
110+
{
105111
AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
112+
AssemblyResources.ToFile(ResourceType.Platform, "git.zip.md5", installDetails.ZipPath, environment);
113+
}
106114
state.GitZipExists = installDetails.GitZipPath.FileExists();
107115

108116
if (!state.GitLfsZipExists)
117+
{
109118
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.ZipPath, environment);
119+
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", installDetails.ZipPath, environment);
120+
}
110121
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
111122
installationTask.UpdateProgress(20, 100);
112123
return state;
@@ -195,9 +206,9 @@ class GitInstallationState
195206

196207
public class GitInstallDetails
197208
{
198-
public const string DefaultGitZipMd5Url = "https://ghfvs-installer.github.com/unity/portable_git/git.zip.MD5.txt";
209+
public const string DefaultGitZipMd5Url = "https://ghfvs-installer.github.com/unity/portable_git/git.zip.md5";
199210
public const string DefaultGitZipUrl = "https://ghfvs-installer.github.com/unity/portable_git/git.zip";
200-
public const string DefaultGitLfsZipMd5Url = "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.MD5.txt";
211+
public const string DefaultGitLfsZipMd5Url = "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.md5";
201212
public const string DefaultGitLfsZipUrl = "https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip";
202213

203214
public const string GitExtractedMD5 = "e6cfc0c294a2312042f27f893dfc9c0a";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3cde251dc13fe09ef62a2a2227fcc310
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[core]
2+
symlinks = false
3+
autocrlf = true
4+
[color]
5+
diff = auto
6+
status = auto
7+
branch = auto
8+
interactive = true
9+
[pack]
10+
packSizeLimit = 2g
11+
[help]
12+
format = html
13+
[http]
14+
sslCAinfo = /ssl/certs/ca-bundle.crt
15+
[diff "astextplain"]
16+
textconv = astextplain
17+
[rebase]
18+
autosquash = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fb5862c66d8d53ba4eb9599419dffa1f
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
105df1302560c5f6aa64d1930284c126
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ea5d5a38a6b9e9bc2b10011602c65a0d

src/tests/IntegrationTests/BaseGitEnvironmentTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ class BaseGitEnvironmentTest : BaseIntegrationTest
77
public override void OnSetup()
88
{
99
base.OnSetup();
10-
Logger.Trace("Extracting Zip File to {0}", TestBasePath);
10+
Logger.Trace($"Extracting {TestZipFilePath} to {TestBasePath}");
1111
ZipHelper.ExtractZipFile(TestZipFilePath, TestBasePath.ToString(), TaskManager.Token, (value, total) => true);
12-
Logger.Trace("Extracted Zip File");
1312
}
1413

1514
public override void OnTearDown()

src/tests/IntegrationTests/BaseIntegrationTest.cs

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
2+
using System.Diagnostics;
23
using NUnit.Framework;
34
using GitHub.Unity;
45
using NCrunch.Framework;
56
using System.Threading;
67
using GitHub.Logging;
78
using System.Linq;
89
using System.IO;
10+
using System.Runtime.CompilerServices;
911

1012
namespace IntegrationTests
1113
{
@@ -78,18 +80,19 @@ protected void InitializeEnvironment(NPath repoPath = null,
7880
initializeRepository);
7981
}
8082

81-
protected void InitializePlatform(NPath repoPath, NPath environmentPath, bool enableEnvironmentTrace, bool initializeRepository = true, bool setupGit = true)
83+
private void InitializePlatform(NPath repoPath, NPath environmentPath, bool enableEnvironmentTrace,
84+
bool setupGit = true, string testName = "")
8285
{
8386
InitializeTaskManager();
84-
InitializeEnvironment(repoPath, environmentPath, enableEnvironmentTrace, initializeRepository);
87+
InitializeEnvironment(repoPath, environmentPath, enableEnvironmentTrace, true);
8588

8689
Platform = new Platform(Environment);
8790
ProcessManager = new ProcessManager(Environment, GitEnvironment, TaskManager.Token);
8891

8992
Platform.Initialize(ProcessManager, TaskManager);
9093

9194
if (setupGit)
92-
SetupGit(Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath());
95+
SetupGit(Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath(), testName);
9396
}
9497

9598
protected void InitializeTaskManager()
@@ -103,9 +106,10 @@ protected IEnvironment InitializePlatformAndEnvironment(NPath repoPath,
103106
NPath environmentPath = null,
104107
bool enableEnvironmentTrace = false,
105108
bool setupGit = true,
106-
Action<IRepositoryManager> onRepositoryManagerCreated = null)
109+
Action<IRepositoryManager> onRepositoryManagerCreated = null,
110+
[CallerMemberName] string testName = "")
107111
{
108-
InitializePlatform(repoPath, environmentPath, enableEnvironmentTrace, setupGit);
112+
InitializePlatform(repoPath, environmentPath, enableEnvironmentTrace, setupGit, testName);
109113

110114
DotGitPath = repoPath.Combine(".git");
111115

@@ -133,15 +137,20 @@ protected IEnvironment InitializePlatformAndEnvironment(NPath repoPath,
133137
return Environment;
134138
}
135139

136-
protected void SetupGit(NPath pathToSetupGitInto)
140+
protected void SetupGit(NPath pathToSetupGitInto, string testName)
137141
{
138142
var autoResetEvent = new AutoResetEvent(false);
139143

140144
var installDetails = new GitInstaller.GitInstallDetails(pathToSetupGitInto, true);
141145

142146
var zipArchivesPath = pathToSetupGitInto.Combine("downloads").CreateDirectory();
147+
148+
Logger.Trace($"Saving git zips into {zipArchivesPath} and unzipping to {pathToSetupGitInto}");
149+
143150
AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment);
151+
AssemblyResources.ToFile(ResourceType.Platform, "git.zip.md5", zipArchivesPath, Environment);
144152
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment);
153+
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", zipArchivesPath, Environment);
145154

146155
var gitInstaller = new GitInstaller(Environment, TaskManager.Token, installDetails);
147156

@@ -155,7 +164,8 @@ protected void SetupGit(NPath pathToSetupGitInto)
155164
autoResetEvent.Set();
156165
};
157166

158-
autoResetEvent.WaitOne();
167+
if (!autoResetEvent.WaitOne(TimeSpan.FromMinutes(1)))
168+
throw new TimeoutException($"Test setup unzipping {zipArchivesPath} to {pathToSetupGitInto} timed out");
159169

160170
if (result == null)
161171
{
@@ -220,5 +230,31 @@ public virtual void OnTearDown()
220230

221231
NPath.FileSystem = null;
222232
}
233+
234+
protected void StartTest(out Stopwatch watch, out ILogging logger, [CallerMemberName] string testName = "test")
235+
{
236+
watch = new Stopwatch();
237+
logger = LogHelper.GetLogger(testName);
238+
logger.Trace("Starting test");
239+
}
240+
241+
protected void EndTest(ILogging logger)
242+
{
243+
logger.Trace("Ending test");
244+
}
245+
246+
protected void StartTrackTime(Stopwatch watch, ILogging logger = null, string message = "")
247+
{
248+
if (!String.IsNullOrEmpty(message))
249+
logger.Trace(message);
250+
watch.Reset();
251+
watch.Start();
252+
}
253+
254+
protected void StopTrackTimeAndLog(Stopwatch watch, ILogging logger)
255+
{
256+
watch.Stop();
257+
logger.Trace($"Time: {watch.ElapsedMilliseconds}");
258+
}
223259
}
224260
}

0 commit comments

Comments
 (0)