Skip to content

Commit

Permalink
Improve reliability in running unit tests
Browse files Browse the repository at this point in the history
This fixes what has been a huge pain for me in running the libgit2sharp unit
tests lately. I think the issue is that different test runners end up
preventing the Resources directory from getting cleaned/deleted. You often
end up having to run the test(s) 2 or 3 times before they will actually run.
The solution in this commit is to create a unique resources directory for
each test run while still trying to cleanup the directories from the
previous run. If there are still issues, we could let the cleanup step
gracefully fail (leaving behind the previous run temp dir) and defer that
cleanup until the next time the tests are run.
  • Loading branch information
tclem authored and nulltoken committed Nov 24, 2011
1 parent 091ea51 commit 2097212
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 177 deletions.
10 changes: 5 additions & 5 deletions LibGit2Sharp.Tests/BlobFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BlobFixture : BaseFixture
[Test]
public void CanGetBlobAsUtf8()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");

Expand All @@ -23,7 +23,7 @@ public void CanGetBlobAsUtf8()
[Test]
public void CanGetBlobSize()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
blob.Size.ShouldEqual(10);
Expand All @@ -33,7 +33,7 @@ public void CanGetBlobSize()
[Test]
public void CanLookUpBlob()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
blob.ShouldNotBeNull();
Expand All @@ -43,7 +43,7 @@ public void CanLookUpBlob()
[Test]
public void CanReadBlobContent()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
byte[] bytes = blob.Content;
Expand All @@ -57,7 +57,7 @@ public void CanReadBlobContent()
[Test]
public void CanReadBlobStream()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");

Expand Down
40 changes: 20 additions & 20 deletions LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void CreatingABranchTriggersTheCreationOfADirectReference()
[Test]
public void CreatingABranchFromANonCommitObjectThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
const string name = "sorry-dude-i-do-not-do-blobs-nor-trees";
Assert.Throws<LibGit2Exception>(() => repo.CreateBranch(name, "refs/tags/point_to_blob"));
Expand All @@ -119,7 +119,7 @@ public void CreatingABranchFromANonCommitObjectThrows()
[Test]
public void CreatingBranchWithUnknownNamedTargetThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Create("my_new_branch", "my_old_branch"));
}
Expand All @@ -128,7 +128,7 @@ public void CreatingBranchWithUnknownNamedTargetThrows()
[Test]
public void CreatingBranchWithUnknownShaTargetThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha));
Assert.Throws<LibGit2Exception>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha.Substring(0, 7)));
Expand All @@ -138,7 +138,7 @@ public void CreatingBranchWithUnknownShaTargetThrows()
[Test]
public void CreatingABranchPointingAtANonCanonicalReferenceThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Create("nocanonicaltarget", "br2"));
}
Expand All @@ -147,7 +147,7 @@ public void CreatingABranchPointingAtANonCanonicalReferenceThrows()
[Test]
public void CreatingBranchWithBadParamsThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<ArgumentNullException>(() => repo.Branches.Create(null, repo.Head.CanonicalName));
Assert.Throws<ArgumentException>(() => repo.Branches.Create(string.Empty, repo.Head.CanonicalName));
Expand All @@ -159,7 +159,7 @@ public void CreatingBranchWithBadParamsThrows()
[Test]
public void CanListAllBranches()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
CollectionAssert.AreEqual(expectedBranches, repo.Branches.Select(b => b.Name).ToArray());

Expand All @@ -170,7 +170,7 @@ public void CanListAllBranches()
[Test]
public void CanListAllBranchesIncludingRemoteRefs()
{
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(Constants.StandardTestRepoPath);
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
using (var repo = new Repository(path.RepositoryPath))
{
var expectedBranchesIncludingRemoteRefs = new[]
Expand All @@ -189,7 +189,7 @@ public void CanListAllBranchesIncludingRemoteRefs()
[Test]
public void CanLookupABranchByItsCanonicalName()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Branch branch = repo.Branches["refs/heads/br2"];
branch.ShouldNotBeNull();
Expand All @@ -207,7 +207,7 @@ public void CanLookupABranchByItsCanonicalName()
[Test]
public void CanLookupLocalBranch()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Branch master = repo.Branches["master"];
master.ShouldNotBeNull();
Expand All @@ -222,7 +222,7 @@ public void CanLookupLocalBranch()
[Test]
public void LookingOutABranchByNameWithBadParamsThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Branch branch;
Assert.Throws<ArgumentNullException>(() => branch = repo.Branches[null]);
Expand All @@ -233,7 +233,7 @@ public void LookingOutABranchByNameWithBadParamsThrows()
[Test]
public void TrackingInformationIsEmptyForNonTrackingBranch()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Branch branch = repo.Branches["test"];
branch.IsTracking.ShouldBeFalse();
Expand All @@ -246,7 +246,7 @@ public void TrackingInformationIsEmptyForNonTrackingBranch()
[Test]
public void CanGetTrackingInformationForTrackingBranch()
{
using (var repo = new Repository(Constants.StandardTestRepoPath))
using (var repo = new Repository(StandardTestRepoPath))
{
Branch master = repo.Branches["master"];
master.IsTracking.ShouldBeTrue();
Expand All @@ -259,7 +259,7 @@ public void CanGetTrackingInformationForTrackingBranch()
[Test]
public void CanWalkCommitsFromAnotherBranch()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Branch master = repo.Branches["test"];
master.Commits.Count().ShouldEqual(2);
Expand All @@ -269,7 +269,7 @@ public void CanWalkCommitsFromAnotherBranch()
[Test]
public void CanWalkCommitsFromBranch()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Branch master = repo.Branches["master"];
master.Commits.Count().ShouldEqual(7);
Expand Down Expand Up @@ -326,7 +326,7 @@ public void CanCheckoutAnArbitraryCommit(string commitPointer)
[Test]
public void CheckingOutANonExistingBranchThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Checkout("i-do-not-exist"));
}
Expand All @@ -335,7 +335,7 @@ public void CheckingOutANonExistingBranchThrows()
[Test]
public void CheckingOutABranchWithBadParamsThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<ArgumentException>(() => repo.Branches.Checkout(string.Empty));
Assert.Throws<ArgumentNullException>(() => repo.Branches.Checkout(null));
Expand All @@ -345,7 +345,7 @@ public void CheckingOutABranchWithBadParamsThrows()
[Test]
public void DeletingABranchWhichIsTheCurrentHeadThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Delete(repo.Head.Name));
}
Expand All @@ -354,7 +354,7 @@ public void DeletingABranchWhichIsTheCurrentHeadThrows()
[Test]
public void DeletingABranchWithBadParamsThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<ArgumentException>(() => repo.Branches.Delete(string.Empty));
Assert.Throws<ArgumentNullException>(() => repo.Branches.Delete(null));
Expand All @@ -364,7 +364,7 @@ public void DeletingABranchWithBadParamsThrows()
[Test]
public void OnlyOneBranchIsTheHead()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Branch head = null;

Expand Down Expand Up @@ -422,7 +422,7 @@ public void CanMoveABranch()
[Test]
public void BlindlyMovingABranchOverAnExistingOneThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Branches.Move("br2", "test"));
}
Expand Down
36 changes: 18 additions & 18 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CommitFixture : BaseFixture
[Test]
public void CanCountCommits()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
repo.Commits.Count().ShouldEqual(7);
}
Expand All @@ -26,7 +26,7 @@ public void CanCountCommits()
[Test]
public void CanCorrectlyCountCommitsWhenSwitchingToAnotherBranch()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
repo.Branches.Checkout("test");
repo.Commits.Count().ShouldEqual(2);
Expand All @@ -42,7 +42,7 @@ public void CanCorrectlyCountCommitsWhenSwitchingToAnotherBranch()
public void CanEnumerateCommits()
{
int count = 0;
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
foreach (Commit commit in repo.Commits)
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public void CanEnumerateCommitsInDetachedHeadState()
[Test]
public void DefaultOrderingWhenEnumeratingCommitsIsTimeBased()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
repo.Commits.SortedBy.ShouldEqual(GitSortOptions.Time);
}
Expand All @@ -81,7 +81,7 @@ public void DefaultOrderingWhenEnumeratingCommitsIsTimeBased()
public void CanEnumerateCommitsFromSha()
{
int count = 0;
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
foreach (Commit commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f" }))
{
Expand All @@ -95,7 +95,7 @@ public void CanEnumerateCommitsFromSha()
[Test]
public void QueryingTheCommitHistoryWithUnknownShaOrInvalidEntryPointThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Commits.QueryBy(new Filter { Since = Constants.UnknownSha }).Count());
Assert.Throws<LibGit2Exception>(() => repo.Commits.QueryBy(new Filter { Since = "refs/heads/deadbeef" }).Count());
Expand All @@ -119,7 +119,7 @@ public void QueryingTheCommitHistoryFromACorruptedReferenceThrows()
[Test]
public void QueryingTheCommitHistoryWithBadParamsThrows()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<ArgumentException>(() => repo.Commits.QueryBy(new Filter { Since = string.Empty }));
Assert.Throws<ArgumentNullException>(() => repo.Commits.QueryBy(new Filter { Since = null }));
Expand All @@ -132,7 +132,7 @@ public void CanEnumerateCommitsWithReverseTimeSorting()
{
expectedShas.Reverse();
int count = 0;
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
foreach (Commit commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time | GitSortOptions.Reverse }))
{
Expand All @@ -147,7 +147,7 @@ public void CanEnumerateCommitsWithReverseTimeSorting()
[Test]
public void CanEnumerateCommitsWithReverseTopoSorting()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
List<Commit> commits = repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time | GitSortOptions.Reverse }).ToList();
foreach (Commit commit in commits)
Expand All @@ -166,7 +166,7 @@ public void CanEnumerateCommitsWithReverseTopoSorting()
public void CanEnumerateCommitsWithTimeSorting()
{
int count = 0;
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
foreach (Commit commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time }))
{
Expand All @@ -181,7 +181,7 @@ public void CanEnumerateCommitsWithTimeSorting()
[Test]
public void CanEnumerateCommitsWithTopoSorting()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
List<Commit> commits = repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Topological }).ToList();
foreach (Commit commit in commits)
Expand Down Expand Up @@ -322,7 +322,7 @@ public void CanEnumerateCommitsFromATagWhichDoesNotPointAtACommit()

private static void AssertEnumerationOfCommits(Func<Repository, Filter> filterBuilder, IEnumerable<string> abbrevIds)
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
AssertEnumerationOfCommitsInRepo(repo, filterBuilder, abbrevIds);
}
Expand All @@ -340,7 +340,7 @@ private static void AssertEnumerationOfCommitsInRepo(Repository repo, Func<Repos
[Test]
public void CanLookupCommitGeneric()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var commit = repo.Lookup<Commit>(sha);
commit.Message.ShouldEqual("testing\n");
Expand All @@ -352,7 +352,7 @@ public void CanLookupCommitGeneric()
[Test]
public void CanReadCommitData()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
GitObject obj = repo.Lookup(sha);
obj.ShouldNotBeNull();
Expand Down Expand Up @@ -383,7 +383,7 @@ public void CanReadCommitData()
[Test]
public void CanReadCommitWithMultipleParents()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var commit = repo.Lookup<Commit>("a4a7dce85cf63874e984719f4fdd239f5145052f");
commit.Parents.Count().ShouldEqual(2);
Expand All @@ -393,7 +393,7 @@ public void CanReadCommitWithMultipleParents()
[Test]
public void CanDirectlyAccessABlobOfTheCommit()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var commit = repo.Lookup<Commit>("4c062a6");

Expand All @@ -407,7 +407,7 @@ public void CanDirectlyAccessABlobOfTheCommit()
[Test]
public void CanDirectlyAccessATreeOfTheCommit()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var commit = repo.Lookup<Commit>("4c062a6");

Expand All @@ -419,7 +419,7 @@ public void CanDirectlyAccessATreeOfTheCommit()
[Test]
public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull()
{
using (var repo = new Repository(Constants.BareTestRepoPath))
using (var repo = new Repository(BareTestRepoPath))
{
var commit = repo.Lookup<Commit>("4c062a6");

Expand Down
Loading

0 comments on commit 2097212

Please sign in to comment.