mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 11:01:28 +03:00
Added thread IsBackground unit test
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Amib.Threading;
|
||||
|
||||
namespace SmartThreadPoolTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for TestThreadIsBackground.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[Category("TestThreadIsBackground")]
|
||||
public class TestThreadIsBackground
|
||||
{
|
||||
[Test]
|
||||
public void TestIsBackground()
|
||||
{
|
||||
CheckIsBackground(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNotIsBackground()
|
||||
{
|
||||
CheckIsBackground(false);
|
||||
}
|
||||
|
||||
private static void CheckIsBackground(bool isBackground)
|
||||
{
|
||||
STPStartInfo stpStartInfo = new STPStartInfo();
|
||||
stpStartInfo.AreThreadsBackground = isBackground;
|
||||
|
||||
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
|
||||
|
||||
IWorkItemResult<bool> wir = stp.QueueWorkItem(() => GetCurrentThreadIsBackground());
|
||||
|
||||
bool resultIsBackground = wir.GetResult();
|
||||
|
||||
stp.WaitForIdle();
|
||||
|
||||
Assert.AreEqual(isBackground, resultIsBackground);
|
||||
}
|
||||
|
||||
private static bool GetCurrentThreadIsBackground()
|
||||
{
|
||||
return Thread.CurrentThread.IsBackground;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user