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
+1 -1
View File
@@ -27,6 +27,7 @@
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
<IsWebBootstrapper>true</IsWebBootstrapper>
<PublishUrl>http://localhost/STPTests/</PublishUrl>
<Install>true</Install>
<InstallFrom>Web</InstallFrom>
@@ -39,7 +40,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>true</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
+41 -1
View File
@@ -13,7 +13,7 @@ namespace SmartThreadPoolTests
[Category("TestCancel")]
public class TestCancel
{
/// <summary>
/// <summary>
/// 1. Create STP in suspended mode
/// 2. Queue work item into the STP
/// 3. Cancel the work item
@@ -153,6 +153,46 @@ namespace SmartThreadPoolTests
Assert.IsTrue(cancelled);
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 CancelInProgressWorkItemSoftWithAbortOnWorkItemOnCancel()
{
bool abortFailed = false;
ManualResetEvent waitToStart = new ManualResetEvent(false);
ManualResetEvent waitToCancel = new ManualResetEvent(false);
SmartThreadPool stp = new SmartThreadPool();
IWorkItemResult wir = stp.QueueWorkItem(
state => {
waitToStart.Set();
waitToCancel.WaitOne();
SmartThreadPool.AbortOnWorkItemOnCancel();
abortFailed = true;
return null;
});
waitToStart.WaitOne();
wir.Cancel(false);
waitToCancel.Set();
stp.WaitForIdle();
Assert.IsTrue(wir.IsCanceled);
Assert.IsFalse(abortFailed);
stp.Shutdown();
}
+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();
}
}
}