Skip to content

Commit 5ce022d

Browse files
committed
Use shared test collection fixture for extractor tests
Replaced individual class fixtures with a shared ExtractorTestCollection using Xunit's [CollectionDefinition] and ICollectionFixture<BaseExtractorTestClass>. This ensures all extractor test classes share a single fixture instance, preventing race conditions and premature deletion of shared resources during parallel test execution.
1 parent 3a348b6 commit 5ce022d

File tree

8 files changed

+30
-7
lines changed

8 files changed

+30
-7
lines changed

RecursiveExtractor.Tests/ExtractorTests/DisposeBehaviorTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
namespace RecursiveExtractor.Tests.ExtractorTests;
1010

11-
public class DisposeBehaviorTests : IClassFixture<BaseExtractorTestClass>
11+
[Collection(ExtractorTestCollection.Name)]
12+
public class DisposeBehaviorTests
1213
{
1314
[Theory]
1415
[InlineData("TestData.7z", 3, false)]

RecursiveExtractor.Tests/ExtractorTests/EncryptedArchiveTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
namespace RecursiveExtractor.Tests.ExtractorTests;
1010

11-
public class EncryptedArchiveTests : IClassFixture<BaseExtractorTestClass>
11+
[Collection(ExtractorTestCollection.Name)]
12+
public class EncryptedArchiveTests
1213
{
1314
[Theory]
1415
[InlineData("TestDataEncryptedZipCrypto.zip")]

RecursiveExtractor.Tests/ExtractorTests/ExpectedNumFilesTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace RecursiveExtractor.Tests.ExtractorTests
1313
{
14-
public class ExpectedNumFilesTests : IClassFixture<BaseExtractorTestClass>
14+
[Collection(ExtractorTestCollection.Name)]
15+
public class ExpectedNumFilesTests
1516
{
1617

1718
/// <summary>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Xunit;
2+
3+
namespace RecursiveExtractor.Tests.ExtractorTests;
4+
5+
/// <summary>
6+
/// Defines a shared test collection so that all extractor test classes share a single
7+
/// <see cref="BaseExtractorTestClass"/> fixture instance. The fixture is created once
8+
/// before the first test runs and disposed once after the last test completes,
9+
/// avoiding the race condition where parallel class-level fixtures prematurely
10+
/// delete the shared temp directory while other classes are still running.
11+
/// </summary>
12+
[CollectionDefinition(Name)]
13+
public class ExtractorTestCollection : ICollectionFixture<BaseExtractorTestClass>
14+
{
15+
public const string Name = "Extractor Tests";
16+
}

RecursiveExtractor.Tests/ExtractorTests/FilterTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace RecursiveExtractor.Tests.ExtractorTests;
99

10-
public class FilterTests : IClassFixture<BaseExtractorTestClass>
10+
[Collection(ExtractorTestCollection.Name)]
11+
public class FilterTests
1112
{
1213
[Theory]
1314
[InlineData("TestData.zip")]

RecursiveExtractor.Tests/ExtractorTests/MiniMagicTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
namespace RecursiveExtractor.Tests.ExtractorTests;
66

7-
public class MiniMagicTests : IClassFixture<BaseExtractorTestClass>
7+
[Collection(ExtractorTestCollection.Name)]
8+
public class MiniMagicTests
89
{
910
[Theory]
1011
[InlineData("TestData.zip", ArchiveFileType.ZIP)]

RecursiveExtractor.Tests/ExtractorTests/TestQuinesAndSlip.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace RecursiveExtractor.Tests.ExtractorTests;
1111

12-
public class TestQuinesAndSlip : IClassFixture<BaseExtractorTestClass>
12+
[Collection(ExtractorTestCollection.Name)]
13+
public class TestQuinesAndSlip
1314
{
1415
public static IEnumerable<object[]> ZipSlipNames
1516
{

RecursiveExtractor.Tests/ExtractorTests/TimeOutTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
namespace RecursiveExtractor.Tests.ExtractorTests;
88

9-
public class TimeOutTests : IClassFixture<BaseExtractorTestClass>
9+
[Collection(ExtractorTestCollection.Name)]
10+
public class TimeOutTests
1011
{
1112
[Theory]
1213
[InlineData("TestData.7z", false)]

0 commit comments

Comments
 (0)