From cb79618316bc21589374ed183363b4c8749cacde Mon Sep 17 00:00:00 2001 From: Koundinya Veluri Date: Fri, 3 Nov 2017 23:16:34 -0700 Subject: [PATCH] Add test for setting min worker threads in thread pool to 1 Related to https://github.com/dotnet/coreclr/issues/14239 Depends on https://github.com/dotnet/coreclr/pull/14864 --- .../tests/ThreadPoolTests.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs index e86ff390cfbf..5e42a9693665 100644 --- a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs +++ b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs @@ -194,6 +194,47 @@ private static void VerifyMaxThreads(int expectedMaxw, int expectedMaxc) Assert.Equal(expectedMaxc, maxc); } + [Fact] + private static void SetMinThreadsTo0Test() + { + int minw, minc, maxw, maxc; + ThreadPool.GetMinThreads(out minw, out minc); + ThreadPool.GetMaxThreads(out maxw, out maxc); + void ResetThreadCounts() + { + Assert.True(ThreadPool.SetMaxThreads(maxw, maxc)); + Assert.True(ThreadPool.SetMinThreads(minw, minc)); + } + + try + { + Assert.True(ThreadPool.SetMinThreads(0, minc)); + Assert.True(ThreadPool.SetMaxThreads(1, maxc)); + + int count = 0; + var done = new ManualResetEvent(false); + WaitCallback callback = null; + callback = state => + { + ++count; + if (count > 100) + { + done.Set(); + } + else + { + ThreadPool.QueueUserWorkItem(callback); + } + }; + ThreadPool.QueueUserWorkItem(callback); + done.WaitOne(ThreadTestHelpers.UnexpectedTimeoutMilliseconds); + } + finally + { + ResetThreadCounts(); + } + } + [Fact] public static void QueueRegisterPositiveAndFlowTest() {