mirror of
https://github.com/farcasclaudiu/SmartThreadPool.git
synced 2026-06-22 11:01:28 +03:00
Added tests for wok item timeout
This commit is contained in:
@@ -27,15 +27,12 @@ namespace SmartThreadPoolTests
|
||||
|
||||
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
|
||||
IWorkItemResult wir = stp.QueueWorkItem(
|
||||
new WorkItemInfo()
|
||||
{
|
||||
Timeout = 1000 },
|
||||
arg =>
|
||||
{
|
||||
hasRun = true;
|
||||
return null;
|
||||
}
|
||||
);
|
||||
new WorkItemInfo() { Timeout = 500 },
|
||||
state =>
|
||||
{
|
||||
hasRun = true;
|
||||
return null;
|
||||
});
|
||||
|
||||
Assert.IsFalse(wir.IsCanceled);
|
||||
|
||||
@@ -76,7 +73,7 @@ namespace SmartThreadPoolTests
|
||||
|
||||
SmartThreadPool stp = new SmartThreadPool();
|
||||
IWorkItemResult wir = stp.QueueWorkItem(
|
||||
new WorkItemInfo() { Timeout = 1000 },
|
||||
new WorkItemInfo() { Timeout = 500 },
|
||||
state =>
|
||||
{
|
||||
waitToStart.Set();
|
||||
@@ -109,7 +106,7 @@ namespace SmartThreadPoolTests
|
||||
SmartThreadPool stp = new SmartThreadPool();
|
||||
IWorkItemResult wir =
|
||||
stp.QueueWorkItem(
|
||||
new WorkItemInfo() { Timeout = 1000 },
|
||||
new WorkItemInfo() { Timeout = 500 },
|
||||
state => 1);
|
||||
|
||||
stp.WaitForIdle();
|
||||
@@ -122,5 +119,42 @@ namespace SmartThreadPoolTests
|
||||
|
||||
stp.Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 1. Create STP
|
||||
/// 2. Queue work item that takes some time
|
||||
/// 3. Wait for it to start
|
||||
/// 4. Cancel the work item (soft)
|
||||
/// 5. Call to AbortOnWorkItemOnCancel
|
||||
/// 5. Wait for the STP to get idle
|
||||
/// 6. Make sure nothing ran in the work item after the AbortOnWorkItemOnCancel
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TimeoutInProgressWorkItemSoftWithAbortOnWorkItemOnCancel()
|
||||
{
|
||||
bool abortFailed = false;
|
||||
ManualResetEvent waitToStart = new ManualResetEvent(false);
|
||||
ManualResetEvent waitToComplete = new ManualResetEvent(false);
|
||||
|
||||
SmartThreadPool stp = new SmartThreadPool();
|
||||
IWorkItemResult wir = stp.QueueWorkItem(
|
||||
new WorkItemInfo() { Timeout = 500 },
|
||||
state =>
|
||||
{
|
||||
waitToStart.Set();
|
||||
Thread.Sleep(1000);
|
||||
SmartThreadPool.AbortOnWorkItemOnCancel();
|
||||
abortFailed = true;
|
||||
return null;
|
||||
});
|
||||
|
||||
waitToStart.WaitOne();
|
||||
|
||||
stp.WaitForIdle();
|
||||
|
||||
Assert.IsTrue(wir.IsCanceled);
|
||||
Assert.IsFalse(abortFailed);
|
||||
stp.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user