|
4 | 4 | using System.IO;
|
5 | 5 | using LibGit2Sharp.Tests.TestHelpers;
|
6 | 6 | using Xunit;
|
| 7 | +using System.Threading.Tasks; |
7 | 8 |
|
8 | 9 | namespace LibGit2Sharp.Tests
|
9 | 10 | {
|
@@ -172,6 +173,49 @@ public void CleanFilterWritesOutputToObjectTree()
|
172 | 173 | }
|
173 | 174 | }
|
174 | 175 |
|
| 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 | + |
175 | 219 | [Fact]
|
176 | 220 | public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
|
177 | 221 | {
|
|
0 commit comments