From 5e8f6abbb0cc06e3b65eedae622f793e672c30a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 10 Apr 2015 13:02:46 +0200 Subject: [PATCH 1/2] Sandbox test repositories in TMP --- LibGit2Sharp.Tests/ShadowCopyFixture.cs | 7 +----- LibGit2Sharp.Tests/TestHelpers/Constants.cs | 26 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/LibGit2Sharp.Tests/ShadowCopyFixture.cs b/LibGit2Sharp.Tests/ShadowCopyFixture.cs index 546b76704..5f57a800c 100644 --- a/LibGit2Sharp.Tests/ShadowCopyFixture.cs +++ b/LibGit2Sharp.Tests/ShadowCopyFixture.cs @@ -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 @@ -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... diff --git a/LibGit2Sharp.Tests/TestHelpers/Constants.cs b/LibGit2Sharp.Tests/TestHelpers/Constants.cs index 46f1d4e49..954ed6aa1 100644 --- a/LibGit2Sharp.Tests/TestHelpers/Constants.cs +++ b/LibGit2Sharp.Tests/TestHelpers/Constants.cs @@ -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))); @@ -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"); + + 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"); + } } } From ce5ab7cdf6ce254c35ac844179e9c48e596e2be6 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Fri, 10 Apr 2015 21:29:05 +0200 Subject: [PATCH 2/2] Garbage collect old test repositories before each run --- LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index 26a27b27c..0ee8a5569 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -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()