Skip to content

Commit 23259c5

Browse files
1 parent 6788f53 commit 23259c5

3 files changed

+124
-0
lines changed

UnitTest1.cs

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
namespace XunitParallelExecutionVsRunnerBug
2+
{
3+
[Collection("Foobar")]
4+
public class UnitTest1
5+
{
6+
private static readonly bool[] TestRun = new bool[typeof(UnitTest1).GetMethods().Length];
7+
8+
[Fact]
9+
public async Task Test1()
10+
{
11+
StartTestRun(1);
12+
13+
await Task.Delay(1000);
14+
15+
EndTestRun(1);
16+
}
17+
18+
[Fact]
19+
public async Task Test2()
20+
{
21+
StartTestRun(2);
22+
23+
await Task.Delay(1000);
24+
25+
EndTestRun(2);
26+
}
27+
28+
[Fact]
29+
public async Task Test3()
30+
{
31+
StartTestRun(3);
32+
33+
await Task.Delay(1000);
34+
35+
EndTestRun(3);
36+
}
37+
38+
[Fact]
39+
public async Task Test4()
40+
{
41+
StartTestRun(4);
42+
43+
await Task.Delay(1000);
44+
45+
EndTestRun(4);
46+
}
47+
48+
private static void StartTestRun(int number)
49+
{
50+
lock (TestRun)
51+
{
52+
// Assert no other tests is running.
53+
for (var i = 0; i < TestRun.Length; i++)
54+
{
55+
Assert.False(TestRun[i], $"The Test{i + 1} is running in parallel with the Test{number}...");
56+
}
57+
58+
TestRun[number - 1] = true;
59+
}
60+
}
61+
62+
private static void EndTestRun(int number)
63+
{
64+
lock (TestRun)
65+
{
66+
TestRun[number - 1] = false;
67+
}
68+
}
69+
}
70+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="coverlet.collector" Version="6.0.2">
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
</PackageReference>
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
18+
<PackageReference Include="xunit" Version="2.9.2" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<Using Include="Xunit" />
27+
</ItemGroup>
28+
29+
</Project>

XunitParallelExecutionVsRunnerBug.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35312.102
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XunitParallelExecutionVsRunnerBug", "XunitParallelExecutionVsRunnerBug.csproj", "{3E72FBEC-495E-49A5-9A13-B3E5FB6147F5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3E72FBEC-495E-49A5-9A13-B3E5FB6147F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3E72FBEC-495E-49A5-9A13-B3E5FB6147F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3E72FBEC-495E-49A5-9A13-B3E5FB6147F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3E72FBEC-495E-49A5-9A13-B3E5FB6147F5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {13E73CFC-36F7-427F-AB33-750E87E84B47}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)