Skip to content

Commit

Permalink
Add failing test proving that filters crash when run concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
niik committed Feb 18, 2016
1 parent 5d44816 commit 45b321b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions LibGit2Sharp.Tests/FilterFixture.cs
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using System.Threading.Tasks;

namespace LibGit2Sharp.Tests
{
Expand Down Expand Up @@ -172,6 +173,49 @@ public void CleanFilterWritesOutputToObjectTree()
}
}

[Fact]
public void CanHandleMultipleSmudgesConcurrently()
{
const string decodedInput = "This is a substitution cipher";
const string encodedInput = "Guvf vf n fhofgvghgvba pvcure";

const string branchName = "branch";

Action<Stream, Stream> smudgeCallback = SubstitutionCipherFilter.RotateByThirteenPlaces;

var filter = new FakeFilter(FilterName, attributes, null, smudgeCallback);
var registration = GlobalSettings.RegisterFilter(filter);

try
{
int count = 30;
var tasks = new Task<FileInfo>[count];

for (int i = 0; i < count; i++)
{
tasks[i] = Task.Factory.StartNew(() =>
{
string repoPath = InitNewRepository();
return CheckoutFileForSmudge(repoPath, branchName, encodedInput);
});
}

Task.WaitAll(tasks);

foreach(var task in tasks)
{
FileInfo expectedFile = task.Result;

string readAllText = File.ReadAllText(expectedFile.FullName);
Assert.Equal(decodedInput, readAllText);
}
}
finally
{
GlobalSettings.DeregisterFilter(registration);
}
}

[Fact]
public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
{
Expand Down

0 comments on commit 45b321b

Please sign in to comment.