Added tests for wok item timeout

This commit is contained in:
Ami Bar
2009-12-20 09:42:44 +02:00
parent ccfd49f237
commit bb25bd62e3
7 changed files with 156 additions and 34 deletions
+45 -11
View File
@@ -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();
}
}
}