8000 Add failing test proving that filters crash when run concurrently · UiPath/libgit2sharp@45b321b · GitHub
[go: up one dir, main page]

Skip to content

Commit 45b321b

Browse files
committed
Add failing test proving that filters crash when run concurrently
1 parent 5d44816 commit 45b321b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

LibGit2Sharp.Tests/FilterFixture.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using LibGit2Sharp.Tests.TestHelpers;
66
using Xunit;
7+
using System.Threading.Tasks;
78

89
namespace LibGit2Sharp.Tests
910
{
@@ -172,6 +173,49 @@ public void CleanFilterWritesOutputToObjectTree()
172173
}
173174
}
174175

176+
[Fact]
177+
public void CanHandleMultipleSmudgesConcurrently()
178+
{
179+
const string decodedInput = "This is a substitution cipher";
180+
const string encodedInput = "Guvf vf n fhofgvghgvba pvcure";
181+
182+
const string branchName = "branch";
183+
184+
Action<Stream, Stream> smudgeCallback = SubstitutionCipherFilter.RotateByThirteenPlaces;
185+
186+
var filter = new FakeFilter(FilterName, attributes, null, smudgeCallback);
187+
var registration = GlobalSettings.RegisterFilter(filter);
188+
189+
try
190+
{
191+
int count = 30;
192+
var tasks = new Task<FileInfo>[count];
193+
194+
for (int i = 0; i < count; i++)
195+
{
196+
tasks[i] = Task.Factory.StartNew(() =>
197+
{
198+
string repoPath = InitNewRepository();
199+
return CheckoutFileForSmudge(repoPath, branchName, encodedInput);
200+
});
201+
}
202+
203+
Task.WaitAll(tasks);
204+
205+
foreach(var task in tasks)
206+
{
207+
FileInfo expectedFile = task.Result;
208+
209+
string readAllText = File.ReadAllText(expectedFile.FullName);
210+
Assert.Equal(decodedInput, readAllText);
211+
}
212+
}
213+
finally
214+
{
215+
GlobalSettings.DeregisterFilter(registration);
216+
}
217+
}
218+
175219
[Fact]
176220
public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
177221
{

0 commit comments

Comments
 (0)
0