mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-28 13:01:05 +03:00
Added thread IsBackground unit test
This commit is contained in:
@@ -111,6 +111,7 @@
|
|||||||
<Compile Include="AssemblyInfo.cs">
|
<Compile Include="AssemblyInfo.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="TestThreadIsBackground.cs" />
|
||||||
<Compile Include="TestThreadApartmentState.cs" />
|
<Compile Include="TestThreadApartmentState.cs" />
|
||||||
<Compile Include="TestParallelMethods.cs" />
|
<Compile Include="TestParallelMethods.cs" />
|
||||||
<Compile Include="TestFalseFillStateWithParams.cs" />
|
<Compile Include="TestFalseFillStateWithParams.cs" />
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Amib.Threading;
|
|||||||
namespace SmartThreadPoolTests
|
namespace SmartThreadPoolTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Summary description for TestThreadPriority.
|
/// Summary description for TestThreadApartment.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
[Category("TestThreadApartment")]
|
[Category("TestThreadApartment")]
|
||||||
@@ -26,7 +26,7 @@ namespace SmartThreadPoolTests
|
|||||||
private static void CheckApartmentState(ApartmentState requestApartmentState)
|
private static void CheckApartmentState(ApartmentState requestApartmentState)
|
||||||
{
|
{
|
||||||
STPStartInfo stpStartInfo = new STPStartInfo();
|
STPStartInfo stpStartInfo = new STPStartInfo();
|
||||||
stpStartInfo.ApartmentState = requestApartmentState;
|
stpStartInfo.ApartmentState = requestApartmentState;
|
||||||
|
|
||||||
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
|
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -89,7 +89,6 @@
|
|||||||
// - Added IsBackground option to threads
|
// - Added IsBackground option to threads
|
||||||
// - Added ApartmentState to threads
|
// - Added ApartmentState to threads
|
||||||
// - Fixed thread creation when queuing many work items at the same time.
|
// - Fixed thread creation when queuing many work items at the same time.
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|||||||
Reference in New Issue
Block a user