8000 Sandbox test repositories in TMP by nulltoken · Pull Request #1018 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

Sandbox test repositories in TMP #1018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions LibGit2Sharp.Tests/ShadowCopyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
Assembly assembly = type.Assembly;

// Build a new domain which will shadow copy assemblies
string cachePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string cachePath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
Directory.CreateDirectory(cachePath);

var setup = new AppDomainSetup
Expand Down Expand Up @@ -51,11 +51,6 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()

// ...but are currently loaded from different locations...
string cachedAssemblyLocation = wrapper.AssemblyLocation;
if (cachedAssemblyLocation.StartsWith("/private"))
{
// On OS X, sometimes you get /private/var/… instead of /var/…, but they map to the same place.
cachedAssemblyLocation = cachedAssemblyLocation.Substring("/private".Length);
}
Assert.NotEqual(sourceAssembly.Location, cachedAssemblyLocation);

// ...that the assembly in the other domain is stored in the shadow copy cache...
Expand Down
15 changes: 15 additions & 0 deletions LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ private static void SetUpTestEnvironment()
SubmoduleTargetTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_target_wd");
AssumeUnchangedRepoWorkingDirPath = Path.Combine(sourceRelativePath, "assume_unchanged_wd");
SubmoduleSmallTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_small_wd");

CleanupTestReposOlderThan(TimeSpan.FromMinutes(15));
}

private static void CleanupTestReposOlderThan(TimeSpan olderThan)
{
var oldTestRepos = new DirectoryInfo(Constants.TemporaryReposPath)
.EnumerateDirectories()
.Where(di => di.CreationTimeUtc < DateTimeOffset.Now.Subtract(olderThan))
.Select(di => di.FullName);

foreach (var dir in oldTestRepos)
{
DirectoryHelper.DeleteDirectory(dir);
}
}

private static bool IsFileSystemCaseSensitiveInternal()
Expand Down
26 changes: 25 additions & 1 deletion LibGit2Sharp.Tests/TestHelpers/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.IO;

namespace LibGit2Sharp.Tests.TestHelpers
{
public static class Constants
{
public const string TemporaryReposPath = "TestRepos";
public static readonly string TemporaryReposPath = BuildPath();
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
public static readonly Identity Identity = new Identity("A. U. Thor", "thor@valhalla.asgard.com");
public static readonly Signature Signature = new Signature(Identity, new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
Expand All @@ -30,5 +31,28 @@ public static Credentials PrivateRepoCredentials(string url, string usernameFrom
{
return null;
}

public static string BuildPath()
{
string tempPath;

var unixPath = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this feedback is a bit late, but here we go:

Elsewhere we use Type type = Type.GetType("Mono.Runtime") to determine if we are running on mono - should we put this logic into a function that can be called? Or maybe this is only expected to succeed when running on Mono and *nix?

Also, might be nice to include a little more documentation around why this extra logic is necessary, where the publicKeytoken was found, (and maybe change the name to BuildTemporaryReposPath).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit different. You could be running with Mono on Windows (lol :D) or embedded systems that don't have Mono.Unix. We're only doing that if we have the supplied functionality.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bit we care about isn't that we're running on mono, but that we can run realpath(), and we only really need it for OS X because that's the one with the silly rewrites of temp paths. Anywhere else we can take it or leave it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation - I think having this captured in code comments could be valuable. Also, it seems we are looking for a version of the assembly with a particular public key - This is because we only expect to work with version built by who ever controls that key?


if (unixPath != null)
{
// We're running on Mono/*nix. Let's unwrap the path
tempPath = (string)unixPath.InvokeMember("GetCompleteRealPath",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy |
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
null, unixPath, new object[] { Path.GetTempPath() });
}
else
{
// We're running on .Net/Windows
tempPath = Path.GetTempPath();
}

return Path.Combine(tempPath, "LibGit2Sharp-TestRepos");
}
}
}
0