Skip to content

Commit 0a392a9

Browse files
committed
fix: serialize integration tests to prevent file locking
Add XUnit collection definitions and [Collection] attributes to all integration test classes to prevent parallel execution. This fixes the file locking issue where multiple tests try to build the same project simultaneously, causing "cannot access file ... being used by another process" errors. Test collections: - SimpleProject: Tests for SimpleProject.csproj run sequentially - MultiTargetProject: Tests for MultiTargetProject.csproj run sequentially - DisabledProject: Tests for DisabledProject.csproj run sequentially - Configuration: Configuration tests run sequentially Tests in different collections can still run in parallel, but tests within a collection are serialized to avoid file contention. This fixes the CS2012 error: "SimpleProject.dll could not be opened for writing" that occurred during local Visual Studio test runs.
1 parent 1cd0d92 commit 0a392a9

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

tests/CycloneDX.MSBuild.Tests/IntegrationTests/ConfigurationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace CycloneDX.MSBuild.Tests.IntegrationTests;
77
/// <summary>
88
/// Tests for various configuration options.
99
/// </summary>
10+
[Collection("Configuration")]
1011
public class ConfigurationTests : IDisposable
1112
{
1213
private readonly string _projectPath;

tests/CycloneDX.MSBuild.Tests/IntegrationTests/DisabledProjectTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace CycloneDX.MSBuild.Tests.IntegrationTests;
77
/// <summary>
88
/// Integration tests for projects with SBOM generation disabled.
99
/// </summary>
10+
[Collection("DisabledProject")]
1011
public class DisabledProjectTests : IDisposable
1112
{
1213
private readonly string _projectPath;

tests/CycloneDX.MSBuild.Tests/IntegrationTests/MultiTargetProjectTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace CycloneDX.MSBuild.Tests.IntegrationTests;
77
/// <summary>
88
/// Integration tests for multi-target framework projects.
99
/// </summary>
10+
[Collection("MultiTargetProject")]
1011
public class MultiTargetProjectTests : IDisposable
1112
{
1213
private readonly string _projectPath;

tests/CycloneDX.MSBuild.Tests/IntegrationTests/SimpleProjectTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace CycloneDX.MSBuild.Tests.IntegrationTests;
77
/// <summary>
88
/// Integration tests for simple single-target projects.
99
/// </summary>
10+
[Collection("SimpleProject")]
1011
public class SimpleProjectTests : IDisposable
1112
{
1213
private readonly string _projectPath;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Xunit;
2+
3+
namespace CycloneDX.MSBuild.Tests.IntegrationTests;
4+
5+
/// <summary>
6+
/// XUnit collection definitions to control test parallelization.
7+
/// Tests in the same collection run sequentially to avoid file locking issues.
8+
/// </summary>
9+
10+
// SimpleProject tests - serialize to avoid file locking on SimpleProject.dll
11+
[CollectionDefinition("SimpleProject")]
12+
public class SimpleProjectCollection
13+
{
14+
}
15+
16+
// MultiTargetProject tests - serialize to avoid file locking
17+
[CollectionDefinition("MultiTargetProject")]
18+
public class MultiTargetProjectCollection
19+
{
20+
}
21+
22+
// DisabledProject tests - serialize to avoid file locking
23+
[CollectionDefinition("DisabledProject")]
24+
public class DisabledProjectCollection
25+
{
26+
}
27+
28+
// Configuration tests can run in parallel with project-specific tests
29+
// but serialize among themselves
30+
[CollectionDefinition("Configuration")]
31+
public class ConfigurationCollection
32+
{
33+
}

0 commit comments

Comments
 (0)