Skip to content

Commit

Permalink
Add test for setting min worker threads in thread pool to 1
Browse files Browse the repository at this point in the history
  • Loading branch information
kouvel committed Nov 4, 2017
1 parent 45b724f commit cb79618
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/System.Threading.ThreadPool/tests/ThreadPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit cb79618

Please sign in to comment.