Skip to content

Commit

Permalink
Make lock-related tests not flaky (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-krystianc authored Mar 31, 2023
1 parent 6e36585 commit 309ab12
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Consul.Test/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ static BaseFixture()
// but on .NETFramework the default limit is sometimes very low (2) so we need to bump it to higher value.
// E.g. https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/System.Web/HttpRuntime.cs#L1200
ServicePointManager.DefaultConnectionLimit = int.MaxValue;

// As for HTTP connections, we need multiple threads to test semaphores and locks.
// XUnit sets the initial number of worker threads to the number of CPU cores.
// Unfortunately, when the initial limit for the ThreadPool is too low, it introduces a risk of a deadlock-like behavior and the tests are timing out.
ThreadPool.GetMinThreads(out var workerThreads, out var completionPortThreads);
if (workerThreads < 4)
{
workerThreads = 4;
ThreadPool.SetMinThreads(workerThreads, completionPortThreads);
}
}

public BaseFixture()
Expand Down

0 comments on commit 309ab12

Please sign in to comment.