Adding method for waiting, with timeout, until a condition is true

This commit is contained in:
Chris Cameron
2017-11-15 10:54:35 -05:00
parent c6aa7d7b3e
commit 3322b2038f
2 changed files with 51 additions and 4 deletions

View File

@@ -4,8 +4,25 @@ using NUnit.Framework;
namespace ICD.Common.Utils.Tests
{
[TestFixture]
public sealed class ThreadingUtilsTest
{
public sealed class ThreadingUtilsTest
{
[Test]
public static void WaitTest()
{
Assert.IsFalse(ThreadingUtils.Wait(() => false, 100));
Assert.IsTrue(ThreadingUtils.Wait(() => true, 100));
bool complete = false;
ThreadingUtils.SafeInvoke(() =>
{
ThreadingUtils.Sleep(50);
complete = true;
});
Assert.IsTrue(ThreadingUtils.Wait(() => complete, 100));
}
[Test]
public void Sleep()
{
@@ -20,7 +37,11 @@ namespace ICD.Common.Utils.Tests
public void SafeInvokeTest()
{
bool result = false;
ThreadingUtils.SafeInvoke(() => { ThreadingUtils.Sleep(100); result = true; });
ThreadingUtils.SafeInvoke(() =>
{
ThreadingUtils.Sleep(100);
result = true;
});
Assert.IsFalse(result);
ThreadingUtils.Sleep(1000);
@@ -31,7 +52,11 @@ namespace ICD.Common.Utils.Tests
public void SafeInvokeParamTest()
{
bool result = false;
ThreadingUtils.SafeInvoke(p => { ThreadingUtils.Sleep(100); result = p; }, true);
ThreadingUtils.SafeInvoke(p =>
{
ThreadingUtils.Sleep(100);
result = p;
}, true);
Assert.IsFalse(result);
ThreadingUtils.Sleep(1000);