Skip to content

Commit b6dabde

Browse files
committed
#2955: Ensure minimum thread pool size (v2)
1 parent 5fe01ff commit b6dabde

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/xunit.execution/Sdk/Frameworks/Runners/XunitTestAssemblyRunner.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,20 @@ private void SetupParallelSemaphore(int maxParallelThreads)
318318
var minThreads = (int)args[0];
319319
var minIOPorts = (int)args[1];
320320

321-
if (minThreads < maxParallelThreads)
321+
var threadFloor = Math.Min(4, maxParallelThreads);
322+
if (minThreads < threadFloor)
322323
{
323324
var setMethod = type.GetRuntimeMethod("SetMinThreads", new[] { typeof(int), typeof(int) });
324325
if (setMethod is null)
325326
throw new InvalidOperationException("Cannot find method: System.Threading.ThreadPool.SetMinThreads");
326327

327-
setMethod.Invoke(null, new object[] { maxParallelThreads, minIOPorts });
328+
setMethod.Invoke(null, new object[] { threadFloor, minIOPorts });
328329
}
329330
#else
330331
ThreadPool.GetMinThreads(out var minThreads, out var minIOPorts);
331-
if (minThreads < maxParallelThreads)
332-
ThreadPool.SetMinThreads(maxParallelThreads, minIOPorts);
332+
var threadFloor = Math.Min(4, maxParallelThreads);
333+
if (minThreads < threadFloor)
334+
ThreadPool.SetMinThreads(threadFloor, minIOPorts);
333335
#endif
334336
}
335337

0 commit comments

Comments
 (0)