MaxParallelThreads does not work with Conservative parallelAlgorithm
Describe the bug I've created small project with Xunit.DependencyInjection v9.8.0 with 2 simple test classes (just copy paste to reproduce the issue) :
using Xunit;
[assembly: CollectionBehavior(DisableTestParallelization = false, MaxParallelThreads = 1)]
namespace Test.Xunit.Project;
public class Class1
{
[Fact]
public async Task TestOne()
{
await Task.Delay(10000);
Assert.True(true);
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit.assert" Version="2.9.3" />
<PackageReference Include="Xunit.DependencyInjection" Version="9.8.0" />
<PackageReference Include="xunit" Version="2.9.3" />
</ItemGroup>
<PropertyGroup>
<ParallelizationMode>Enhance</ParallelizationMode>
</PropertyGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
When I run both classes, I expect that they are run sequentially (because MaxParallelThreads = 1), but they run in parallel. Meanwhile, when I use the xunit package without your library, it works perfectly, running as many tests as I specify in MaxParallelThreads.
I saw a similar issue which was closed: https://github.com/pengweiqhca/Xunit.DependencyInjection/issues/111#issuecomment-2109083805, but this does not work for me.
Could you please elaborate and suggest a fix?
Hi @pengweiqhca, any updates on this?
9.9.0 fixed.
Something is amiss with 9.9.0. For me it breaks running tests in parallel. They do run in parallel in 9.7.0.
In 10.x with xUnit 3, I can't run in parallel too, there's any updates?
Something is amiss with 9.9.0. For me it breaks running tests in parallel. They do run in parallel in 9.7.0.
@rramer-web-com Try 9.9.1
In 10.x with xUnit 3, I can't run in parallel too, there's any updates?
@gilmar-sales Try 10.4.1
I've figured out what's going on, my tests are spending more time because it's parallelizing tests inside a collection and others collections doesn't run at the same time.
Consider that 4 test collections has only 3 test cases each, 9 of 12 cores are in idle mode. in the 9.9.1 the tests cases and collections run in parallel, using the 12 cores...
I've created a test case to verify this behaviour: https://github.com/gilmar-sales/Xunit.DependencyInjection/commit/f3248c9b13950410423623cdc480ba83fb3c75e3
I created an test case to verify this behaviour: gilmar-sales@f3248c9
You should use Assembly Fixtures or Collection Fixtures.
In 10.x with xUnit 3, I can't run in parallel too, there's any updates?
@gilmar-sales Try 10.4.1
I've figured out what's going on, my tests are spending more time because it's parallelizing tests inside a collection and others collections doesn't run at the same time.
Consider that 4 test collections has only 3 test cases each, 9 of 12 cores are in idle mode. in the 9.9.1 the tests cases and collections run in parallel, using the 12 cores...
TestProject10-4-1.zip is fixed with 10.4.2
Tested 10.4.2 and worked to both cases, limiting max parallel threads and full parallelization