This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Run_When_Work_Canceled_And_Zero_Tasks_Then_Method_Returns_Immediately() | |
{ | |
const double RUN_MAX_DURATION_S = 0.5; | |
var work = new Work(m_scheduler); | |
work.Dispose(); | |
var time = StopWatchUtils.MeasureActionTime(() => m_scheduler.Run()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Run_When_Work_Exists_And_Zero_Tasks_Then_Method_Does_Not_Return() | |
{ | |
const int WORK_CANCEL_DELAY_MS = 3000; | |
const double RUN_MIN_DURATION_S = 2.0; | |
var time = StopWatchUtils.MeasureActionTime(() => | |
{ | |
cancelWorkAfterTimeout(WORK_CANCEL_DELAY_MS); | |
m_scheduler.Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Run_When_More_Tasks_Added_And_Cancel_Work_Then_All_Tasks_Are_Executed() | |
{ | |
bool wasTask1Called = false; | |
bool wasTask2Called = false; | |
m_scheduler.Dispatch(() => | |
{ | |
wasTask1Called = true; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Run_When_Zero_Tasks_Added_And_Cancel_Work_Then_Returns_Zero() | |
{ | |
cancelWorkAfterTimeout(); | |
var result = m_scheduler.Run(); | |
Assert.AreEqual(0, result); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Run_When_One_Task_Added_And_Cancel_Work_Then_Returns_One() | |
{ | |
m_scheduler.Dispatch(() => | |
{ | |
}); | |
cancelWorkAfterTimeout(); | |
var result = m_scheduler.Run(); | |
Assert.AreEqual(1, result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Run_When_More_Tasks_Added_Then_All_Tasks_Are_Executed() | |
{ | |
bool wasTask1Called = false; | |
bool wasTask2Called = false; | |
m_scheduler.Dispatch(() => | |
{ | |
wasTask1Called = true; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Run_When_One_Task_Added_Then_Returns_One() | |
{ | |
const int NUMBER_OF_SCHEDULED_TASKS = 1; | |
m_scheduler.Dispatch(() => | |
{ | |
}); | |
var result = m_scheduler.Run(); | |
Assert.AreEqual(NUMBER_OF_SCHEDULED_TASKS, result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void Run_When_Zero_Tasks_Added_Then_Returns_Zero() | |
{ | |
var result = m_scheduler.Run(); | |
Assert.AreEqual(0, result); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ProxyScheduler m_proxyScheduler; | |
private IoServiceScheduler m_scheduler; | |
protected override ITaskScheduler Scheduler | |
{ | |
get | |
{ | |
return m_scheduler; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Collections.Generic; | |
using System.Threading; | |
namespace RStein.Async.Schedulers | |
{ | |
public sealed class Work : IDisposable | |
{ | |
private readonly CancellationTokenSource m_cancelTokenSource; |