diff options
author | Koundinya Veluri <kouvel@users.noreply.github.com> | 2017-11-15 06:50:26 +0300 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2017-11-15 06:50:26 +0300 |
commit | 42720da80019ebc63c1757510f41c4dc6bd27ca3 (patch) | |
tree | cf429c2fbbf4d39a8e8a57292165f70c3125df7b /src/System.Threading.ThreadPool | |
parent | e880294f5bd3b907dfc7f653e2b4f85717552db8 (diff) |
Add test for setting min worker threads in thread pool to 0 (#25061)
* Add test for setting min worker threads in thread pool to 0
Related to https://github.com/dotnet/coreclr/issues/14239
Depends on https://github.com/dotnet/coreclr/pull/14864
* Add a verification removed in https://github.com/dotnet/corefx/pull/25144
* Address feedback
Diffstat (limited to 'src/System.Threading.ThreadPool')
-rw-r--r-- | src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs index 16476ca6c2..bc2a0fb172 100644 --- a/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs +++ b/src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs @@ -87,14 +87,6 @@ namespace System.Threading.ThreadPools.Tests int minw, minc, maxw, maxc; ThreadPool.GetMinThreads(out minw, out minc); ThreadPool.GetMaxThreads(out maxw, out maxc); - Action resetThreadCounts = - () => - { - Assert.True(ThreadPool.SetMaxThreads(maxw, maxc)); - VerifyMaxThreads(maxw, maxc); - Assert.True(ThreadPool.SetMinThreads(minw, minc)); - VerifyMinThreads(minw, minc); - }; try { @@ -142,7 +134,10 @@ namespace System.Threading.ThreadPools.Tests } finally { - resetThreadCounts(); + Assert.True(ThreadPool.SetMaxThreads(maxw, maxc)); + VerifyMaxThreads(maxw, maxc); + Assert.True(ThreadPool.SetMinThreads(minw, minc)); + VerifyMinThreads(minw, minc); } } @@ -156,25 +151,21 @@ namespace System.Threading.ThreadPools.Tests int minw, minc, maxw, maxc; ThreadPool.GetMinThreads(out minw, out minc); ThreadPool.GetMaxThreads(out maxw, out maxc); - Action resetThreadCounts = - () => - { - Assert.True(ThreadPool.SetMaxThreads(maxw, maxc)); - VerifyMaxThreads(maxw, maxc); - Assert.True(ThreadPool.SetMinThreads(minw, minc)); - VerifyMinThreads(minw, minc); - }; try { Assert.True(ThreadPool.SetMinThreads(0, 0)); + VerifyMinThreads(1, 1); Assert.False(ThreadPool.SetMaxThreads(0, 1)); Assert.False(ThreadPool.SetMaxThreads(1, 0)); VerifyMaxThreads(maxw, maxc); } finally { - resetThreadCounts(); + Assert.True(ThreadPool.SetMaxThreads(maxw, maxc)); + VerifyMaxThreads(maxw, maxc); + Assert.True(ThreadPool.SetMinThreads(minw, minc)); + VerifyMinThreads(minw, minc); } } @@ -195,6 +186,44 @@ namespace System.Threading.ThreadPools.Tests } [Fact] + [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Triggers an assertion failure.")] + private static void SetMinThreadsTo0Test() + { + int minw, minc, maxw, maxc; + ThreadPool.GetMinThreads(out minw, out minc); + ThreadPool.GetMaxThreads(out maxw, out maxc); + + 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 + { + Assert.True(ThreadPool.SetMaxThreads(maxw, maxc)); + Assert.True(ThreadPool.SetMinThreads(minw, minc)); + } + } + + [Fact] public static void QueueRegisterPositiveAndFlowTest() { var asyncLocal = new AsyncLocal<int>(); |