mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-23 13:00:38 +03:00
v1.0
SmartThreadPool v1.0
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Amib.Threading;
|
||||
|
||||
namespace SmartThreadPoolTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for TestThreadPriority.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[Category("TestThreadPriority")]
|
||||
public class TestThreadPriority
|
||||
{
|
||||
[Test]
|
||||
public void TestDefaultPriority()
|
||||
{
|
||||
SmartThreadPool stp = new SmartThreadPool();
|
||||
|
||||
IWorkItemResult wir = stp.QueueWorkItem(new WorkItemCallback(DoSomeWork));
|
||||
ThreadPriority currentThreadPriority = (ThreadPriority)wir.GetResult();
|
||||
|
||||
Assert.AreEqual(currentThreadPriority, SmartThreadPool.DefaultThreadPriority);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPriorities()
|
||||
{
|
||||
ThreadPriority [] priorities =
|
||||
{
|
||||
ThreadPriority.Lowest,
|
||||
ThreadPriority.BelowNormal,
|
||||
ThreadPriority.Normal,
|
||||
ThreadPriority.AboveNormal,
|
||||
ThreadPriority.Highest,
|
||||
};
|
||||
|
||||
foreach(ThreadPriority priority in priorities)
|
||||
{
|
||||
CheckSinglePriority(priority);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckSinglePriority(ThreadPriority threadPriority)
|
||||
{
|
||||
STPStartInfo stpStartInfo = new STPStartInfo();
|
||||
stpStartInfo.ThreadPriority = threadPriority;
|
||||
|
||||
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
|
||||
|
||||
IWorkItemResult wir = stp.QueueWorkItem(new WorkItemCallback(DoSomeWork));
|
||||
ThreadPriority currentThreadPriority = (ThreadPriority)wir.GetResult();
|
||||
|
||||
Assert.AreEqual(currentThreadPriority, threadPriority);
|
||||
}
|
||||
|
||||
private object DoSomeWork(object state)
|
||||
{
|
||||
return Thread.CurrentThread.Priority;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user