meziantou / Meziantou.Xunit.ParallelTestFramework

Run xUnit test cases in parallel
MIT License
156 stars 6 forks source link

Parallel Options: MaxDegreeOfParallelism? #4

Closed InsomniumBR closed 1 year ago

InsomniumBR commented 1 year ago

Hello,

First thanks for that great library, it fits very well! Do you think we can have in the future a way to control the max threads running concurrently?

I don't know if it should work, but I have tried using the attribute below and it didn't work for me: [assembly: CollectionBehavior(MaxParallelThreads = n)]

Best,

meziantou commented 1 year ago

I think you can use the configuration provided by xUnit. You can create a file named xunit.runner.json with the following content:

{
  "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
  "maxParallelThreads": 10
}

Documentation: https://xunit.net/docs/configuration-files

InsomniumBR commented 1 year ago

Hello @meziantou , thanks for your quickly reply.

Unfortunately, I tried that too and it didn't work for me. I was checking the documentation you sent me and I see that the "default behaviour" for the maxParallelThreads in version 2.4.3 (which I am currently using) would be to use the number of my logical processors, that currently are 16. But even that does not seem to be happening if you check the image below I can count at least more than 20 running together.

image

What is strange is that I have tried with your sample of unit tests and the json configuration file, in the same class, and with this sample it seems to work perfectly:

    [Theory]
    [InlineData(0), InlineData(1), InlineData(2)]
    public void Test3(int value) => Thread.Sleep(2000);

Maybe my tests are heavy and its taking time to update in the UI that they have finished besides limiting the threads. But anyway it should be something specific here, we can close the issue in my perspective.