Skip to content

Commit e20f72b

Browse files
committed
Added another test to the IsolatedUnitTest.
1 parent dcb47d0 commit e20f72b

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

tests/Magick.NET.Tests/Coders/ThePdfCoder.cs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,55 @@
44
using System.Threading.Tasks;
55
using ImageMagick;
66
using Xunit;
7-
using Xunit.Sdk;
87

98
namespace Magick.NET.Tests;
109

10+
[Collection(nameof(IsolatedUnitTest))]
1111
public partial class ThePdfCoder
1212
{
1313
[Fact]
1414
public async Task ShouldReadFileMultithreadedCorrectly()
1515
{
1616
Assert.SkipUnless(Ghostscript.IsAvailable, "Ghostscript is not available");
1717

18-
var results = new Task[3];
19-
20-
for (var i = 0; i < results.Length; ++i)
18+
await IsolatedUnitTest.Execute(static async () =>
2119
{
22-
results[i] = Task.Run(
23-
() =>
24-
{
25-
using var image = new MagickImage();
26-
image.Read(Files.Coders.CartoonNetworkStudiosLogoAI);
27-
28-
Assert.Equal(765U, image.Width);
29-
Assert.Equal(361U, image.Height);
30-
Assert.Equal(MagickFormat.Ai, image.Format);
31-
},
32-
TestContext.Current.CancellationToken);
20+
var results = new Task[3];
21+
22+
for (var i = 0; i < results.Length; ++i)
23+
{
24+
results[i] = Task.Run(
25+
() =>
26+
{
27+
using var image = new MagickImage();
28+
image.Read(Files.Coders.CartoonNetworkStudiosLogoAI);
29+
30+
Assert.Equal(765U, image.Width);
31+
Assert.Equal(361U, image.Height);
32+
Assert.Equal(MagickFormat.Ai, image.Format);
33+
},
34+
TestContext.Current.CancellationToken);
3335
}
3436

35-
for (var i = 0; i < results.Length; ++i)
36-
{
37-
await results[i];
38-
}
37+
for (var i = 0; i < results.Length; ++i)
38+
{
39+
await results[i];
40+
}
41+
});
3942
}
4043

4144
[Fact]
4245
public void ShouldReturnTheCorrectFormatForAiFile()
4346
{
4447
Assert.SkipUnless(Ghostscript.IsAvailable, "Ghostscript is not available");
4548

46-
using var image = new MagickImage(Files.Coders.CartoonNetworkStudiosLogoAI);
49+
IsolatedUnitTest.Execute(static () =>
50+
{
51+
using var image = new MagickImage(Files.Coders.CartoonNetworkStudiosLogoAI);
4752

48-
Assert.Equal(765U, image.Width);
49-
Assert.Equal(361U, image.Height);
50-
Assert.Equal(MagickFormat.Ai, image.Format);
53+
Assert.Equal(765U, image.Width);
54+
Assert.Equal(361U, image.Height);
55+
Assert.Equal(MagickFormat.Ai, image.Format);
56+
});
5157
}
5258
}

tests/Magick.NET.Tests/IsolatedUnitTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Threading;
6+
using System.Threading.Tasks;
67
using Xunit;
78

89
namespace Magick.NET.Tests;
@@ -24,4 +25,17 @@ public static void Execute(Action action)
2425
_semaphore.Release();
2526
}
2627
}
28+
29+
public static async Task Execute(Func<Task> action)
30+
{
31+
await _semaphore.WaitAsync();
32+
try
33+
{
34+
await action();
35+
}
36+
finally
37+
{
38+
_semaphore.Release();
39+
}
40+
}
2741
}

0 commit comments

Comments
 (0)