public void CanExtendTwice( ) { int i = 0; ActionTask a = new ActionTask((task) => i = 1, false); a.Extend((task) => i++); a.Extend((task) => i++); (a as ITask).Start(); Assert.AreEqual(3, i, "Looks like a continued task doesn't actually continue multiple times."); }
public void CanAbort( ) { int i = 0; ActionTask a = new ActionTask((task) => i = 1, false); a.Abort(); Assert.IsTrue(a.Aborted, "Task doesn't think it was aborted."); ActionTask b = new ActionTask((task) => { i = 2; task.Abort(); }, false); b.Extend((task) => { if (!task.Aborted) { i = 3; } }); (b as ITask).Start(); Assert.IsTrue(b.Aborted, "Task doesn't think it was aborted after continuation."); Assert.IsTrue(b.IsCompleted, "Task thinks it didn't complete after abortion."); Assert.AreEqual(2, i, "Task's aborted flag didn't set correctly."); }
public void NappingTestsDontCountTowardsLimit( ) { int i = 0; um = new UnityManager(1); ActionTask task = new ActionTask((_) => _.IsNapping = true, false); task.Extend((_) => i = 100); um.EnqueueTask(task); for (int j = 0; j < 5; j++) { ITask t = new ActionTask((_) => i++, false); um.EnqueueTask(t); } um.UnsafeUpdate(); Assert.IsTrue(task.IsNapping, "Task didn't start napping."); for (int j = 0; j < 5; j++) { um.UnsafeUpdate(); Assert.AreEqual(j + 1, i, "Didn't just run 1."); } task.IsNapping = false; um.UnsafeUpdate(); Assert.AreEqual(100, i, "Didn't run awakened task."); }
public void CanNapTask( ) { int i = 0; ActionTask task = new ActionTask(( _ ) => _.IsNapping = true, false); task.Extend(( _ ) => i = 5); tm.EnqueueTask(task); tm.UnsafeUpdate(); for ( int ms = 0; ms < 1000; ms += 1 ) { System.Threading.Thread.Sleep(1); if ( task.IsNapping ) break; } Assert.IsTrue(task.IsNapping, "Task not napping."); Assert.AreEqual(0, i, "Task extension ran even though it's napping."); task.IsNapping = false; tm.UnsafeUpdate(); for ( int ms = 0; ms < 1000; ms += 1 ) { System.Threading.Thread.Sleep(1); if ( task.IsCompleted ) break; } Assert.IsTrue(task.IsCompleted, "Task never completed."); Assert.AreEqual(5, i, "Task thought it completed, but did not run"); }
public void DedicatedTasksContinueAfterNapping( ) { int i = 0; ActionTask task = new ActionTask((_) => _.IsNapping = true, false); task.Extend((_) => i = 5); tm.SpawnDedicatedThread(task); for (int ms = 0; ms < 1000; ms += 1) { System.Threading.Thread.Sleep(1); if (task.IsNapping) { break; } } Assert.IsTrue(task.IsNapping, "Task didn't nap."); Assert.AreEqual(0, i, "Task ran while napping."); task.IsNapping = false; for (int ms = 0; ms < 1000; ms += 1) { System.Threading.Thread.Sleep(1); if (task.IsCompleted) { break; } } Assert.AreEqual(5, i, "Task didn't run after napping."); }
public void TasksRequeueOnExtensionCorrectly( ) { int i = 0; ActionTask task = Hikari.ScheduleUnity((_) => { i++; System.Threading.Thread.Sleep(100); i++; }); Hikari.Instance.Update(); task.Extend((_) => i++); Hikari.Instance.Update(); for (int h = 0; h < 200; h++) { if (task.IsCompleted) { break; } else { System.Threading.Thread.Sleep(1); } } Assert.AreEqual(3, i, "Task didn't run correctly when extended during runtime."); Assert.IsTrue(task.IsCompleted, "Task did not report completion."); task.Extend((_) => i++); Hikari.Instance.Update(); for (int h = 0; h < 200; h++) { if (task.IsCompleted) { break; } else { System.Threading.Thread.Sleep(1); } } Assert.AreEqual(4, i, "Task didn't run correctly when extended after runtime."); Assert.IsTrue(task.IsCompleted, "Task did not report completion."); }
public void ExtendsTask( ) { int i = 0; ActionTask a = new ActionTask((task) => i = 1, false); a.Extend((task) => i++); (a as ITask).Start(); Assert.AreEqual(2, i, "Looks like a continued task doesn't actually continue."); }
public void NappingFunctions( ) { int i = 0; ActionTask a = new ActionTask((task) => task.IsNapping = true, false); a.Extend((task) => i++); a.Extend((task) => i++); bool result = (a as ITask).Start(); Assert.IsTrue(a.IsNapping, "Doesn't think it's napping..."); Assert.IsFalse(a.IsCompleted, "Thinks its done while napping."); Assert.AreEqual(0, i, "Ran extensions while napping."); Assert.IsTrue(result, "Didn't report it was napping."); a.IsNapping = false; result = (a as ITask).Start(); Assert.AreEqual(2, i, "After napping didn't continue correctly."); Assert.IsTrue(a.IsCompleted, "Doesn't think its done after napping."); Assert.IsFalse(result, "Reported it was still napping."); }
public void CanCancelExtensionsOnAbort( ) { int i = 0; ActionTask b = new ActionTask(( task ) => { i = 2; task.Abort(); }, false, true); b.Extend(( task ) => i = 4); (b as ITask).Start(); Assert.AreEqual(2, i, "Task didn't correctly cancel extensions when aborted."); }
public void CanContinueInTask( ) { int i = 0; ActionTask a = new ActionTask(( task ) => i = 1, false); a.Extend(( task ) => { i++; task.Extend(( task2 ) => i++); }); (a as ITask).Start(); Assert.AreEqual(3, i, "Looks like an extended task doesn't actually continue, when extended in the task."); }
public void CanCancelExtensions( ) { int i = 0; ActionTask a = new ActionTask(( task ) => { i = 1; task.CancelExtensions(); }, false); a.Extend(( task ) => i = 3); (a as ITask).Start(); Assert.AreEqual(1, i, "Task didn't correctly cancel extensions."); }
public void CanContinueInTask( ) { int i = 0; ActionTask a = new ActionTask((task) => i = 1, false); a.Extend((task) => { i++; task.Extend((task2) => i++); }); (a as ITask).Start(); Assert.AreEqual(3, i, "Looks like an extended task doesn't actually continue, when extended in the task."); }
public void CanCancelExtensions( ) { int i = 0; ActionTask a = new ActionTask((task) => { i = 1; task.CancelExtensions(); }, false); a.Extend((task) => i = 3); (a as ITask).Start(); Assert.AreEqual(1, i, "Task didn't correctly cancel extensions."); }
public void CanCancelExtensionsOnAbort( ) { int i = 0; ActionTask b = new ActionTask((task) => { i = 2; task.Abort(); }, false, true); b.Extend((task) => i = 4); (b as ITask).Start(); Assert.AreEqual(2, i, "Task didn't correctly cancel extensions when aborted."); }
public void LetsOthersUseNappingThreadsCorrectly( ) { int i = 0; object _lock = new object(); ThreadManager tman = new ThreadManager(1, 1); // Using this to test interaction very specifically. tman.WaitForThreadSpawns(); ActionTask task = new ActionTask((_) => { _.IsNapping = true; }, false); task.Extend((_) => i = 100); tman.EnqueueTask(task); for (int j = 0; j < 10; j++) { tman.EnqueueTask(new ActionTask((_) => { lock (_lock) i++; }, false)); } tman.UnsafeUpdate(); for (int j = 0; j < 100; j++) { if (task.IsNapping) { break; } else { System.Threading.Thread.Sleep(1); } } for (int j = 0; j < 10; j++) { tman.UnsafeUpdate(); System.Threading.Thread.Sleep(1); lock (_lock) Assert.AreEqual(j + 1, i, "Ran some number other than 1 of the Tasks at once on update #" + j); } task.IsNapping = false; tman.UnsafeUpdate(); System.Threading.Thread.Sleep(1); Assert.AreEqual(100, i, "Did not run awakened Task."); tman.Dispose(); }
public void CanNapTask( ) { int i = 0; ActionTask task = new ActionTask(( _ ) => _.IsNapping = true, false); task.Extend(( _ ) => i = 5); um.EnqueueTask(task); um.UnsafeUpdate(); Assert.IsTrue(task.IsNapping, "Task not napping."); Assert.AreEqual(0, i, "Task extension ran even though it's napping."); task.IsNapping = false; um.UnsafeUpdate(); Assert.IsTrue(task.IsCompleted, "Task never completed."); Assert.AreEqual(5, i, "Task thought it completed, but did not run"); }
public void CanNapTask( ) { int i = 0; ActionTask task = new ActionTask((_) => _.IsNapping = true, false); task.Extend((_) => i = 5); um.EnqueueTask(task); um.UnsafeUpdate(); Assert.IsTrue(task.IsNapping, "Task not napping."); Assert.AreEqual(0, i, "Task extension ran even though it's napping."); task.IsNapping = false; um.UnsafeUpdate(); Assert.IsTrue(task.IsCompleted, "Task never completed."); Assert.AreEqual(5, i, "Task thought it completed, but did not run"); }
public void CanAbort( ) { int i = 0; ActionTask a = new ActionTask(( task ) => i = 1, false); a.Abort(); Assert.IsTrue(a.Aborted, "Task doesn't think it was aborted."); ActionTask b = new ActionTask(( task ) => { i = 2; task.Abort(); }, false); b.Extend(( task ) => { if ( !task.Aborted ) i = 3; }); (b as ITask).Start(); Assert.IsTrue(b.Aborted, "Task doesn't think it was aborted after continuation."); Assert.IsTrue(b.IsCompleted, "Task thinks it didn't complete after abortion."); Assert.AreEqual(2, i, "Task's aborted flag didn't set correctly."); }
public void CanNapTask( ) { int i = 0; ActionTask task = new ActionTask((_) => _.IsNapping = true, false); task.Extend((_) => i = 5); tm.EnqueueTask(task); tm.UnsafeUpdate(); for (int ms = 0; ms < 1000; ms += 1) { System.Threading.Thread.Sleep(1); if (task.IsNapping) { break; } } Assert.IsTrue(task.IsNapping, "Task not napping."); Assert.AreEqual(0, i, "Task extension ran even though it's napping."); task.IsNapping = false; tm.UnsafeUpdate(); for (int ms = 0; ms < 1000; ms += 1) { System.Threading.Thread.Sleep(1); if (task.IsCompleted) { break; } } Assert.IsTrue(task.IsCompleted, "Task never completed."); Assert.AreEqual(5, i, "Task thought it completed, but did not run"); }
public void NappingFunctions( ) { int i = 0; ActionTask a = new ActionTask(( task ) => task.IsNapping = true, false); a.Extend(( task ) => i++); a.Extend(( task ) => i++); bool result = (a as ITask).Start(); Assert.IsTrue(a.IsNapping, "Doesn't think it's napping..."); Assert.IsFalse(a.IsCompleted, "Thinks its done while napping."); Assert.AreEqual(0, i, "Ran extensions while napping."); Assert.IsTrue(result, "Didn't report it was napping."); a.IsNapping = false; result = (a as ITask).Start(); Assert.AreEqual(2, i, "After napping didn't continue correctly."); Assert.IsTrue(a.IsCompleted, "Doesn't think its done after napping."); Assert.IsFalse(result, "Reported it was still napping."); }
public void ExtendsTask( ) { int i = 0; ActionTask a = new ActionTask(( task ) => i = 1, false); a.Extend(( task ) => i++); (a as ITask).Start(); Assert.AreEqual(2, i, "Looks like a continued task doesn't actually continue."); }
public void LetsOthersUseNappingThreadsCorrectly( ) { int i = 0; object _lock = new object(); ThreadManager tman = new ThreadManager(1, 1); // Using this to test interaction very specifically. tman.WaitForThreadSpawns(); ActionTask task = new ActionTask(( _ ) => { _.IsNapping = true; }, false); task.Extend(( _ ) => i = 100); tman.EnqueueTask(task); for ( int j = 0; j < 10; j++ ) tman.EnqueueTask(new ActionTask(( _ ) => { lock ( _lock ) i++; }, false)); tman.UnsafeUpdate(); for ( int j = 0; j < 100; j++ ) if ( task.IsNapping ) break; else System.Threading.Thread.Sleep(1); for ( int j = 0; j < 10; j++ ) { tman.UnsafeUpdate(); System.Threading.Thread.Sleep(1); lock ( _lock ) Assert.AreEqual(j + 1, i, "Ran some number other than 1 of the Tasks at once on update #" + j); } task.IsNapping = false; tman.UnsafeUpdate(); System.Threading.Thread.Sleep(1); Assert.AreEqual(100, i, "Did not run awakened Task."); tman.Dispose(); }
public void DedicatedTasksContinueAfterNapping( ) { int i = 0; ActionTask task = new ActionTask(( _ ) => _.IsNapping = true, false); task.Extend(( _ ) => i = 5); tm.SpawnDedicatedThread(task); for ( int ms = 0; ms < 1000; ms += 1 ) { System.Threading.Thread.Sleep(1); if ( task.IsNapping ) break; } Assert.IsTrue(task.IsNapping, "Task didn't nap."); Assert.AreEqual(0, i, "Task ran while napping."); task.IsNapping = false; for ( int ms = 0; ms < 1000; ms += 1 ) { System.Threading.Thread.Sleep(1); if ( task.IsCompleted ) break; } Assert.AreEqual(5, i, "Task didn't run after napping."); }
public void CanExtendTwice( ) { int i = 0; ActionTask a = new ActionTask(( task ) => i = 1, false); a.Extend(( task ) => i++); a.Extend(( task ) => i++); (a as ITask).Start(); Assert.AreEqual(3, i, "Looks like a continued task doesn't actually continue multiple times."); }
public void NappingTestsDontCountTowardsLimit( ) { int i = 0; um = new UnityManager(1); ActionTask task = new ActionTask(( _ ) => _.IsNapping = true, false); task.Extend(( _ ) => i = 100); um.EnqueueTask(task); for ( int j = 0; j < 5; j++ ) { ITask t = new ActionTask(( _ ) => i++, false); um.EnqueueTask(t); } um.UnsafeUpdate(); Assert.IsTrue(task.IsNapping, "Task didn't start napping."); for ( int j = 0; j < 5; j++ ) { um.UnsafeUpdate(); Assert.AreEqual(j + 1, i, "Didn't just run 1."); } task.IsNapping = false; um.UnsafeUpdate(); Assert.AreEqual(100, i, "Didn't run awakened task."); }