public IEnumerator TestMultiThreadParallelTaskReset() { var test = new MultiThreadedParallelTaskCollection("test", 4, false); Token token = new Token(); int done = 0; test.onComplete += () => done++; test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); test.Run(); yield return(new WaitForSeconds(0.5f)); token.count = 3; test.Stop(); test.Complete(); test.Dispose(); Assert.That(done == 1); Assert.AreEqual(4, token.count); }
void OnDisable() { //the application is shutting down. This is not that necessary in a //standalone client, but necessary to stop the thread when the //application is stopped in the Editor to stop all the threads. //tbh Unity should implement something to shut down the //threads started by the running application _multiParallelTasks.Dispose(); Debug.Log("clean up"); TaskRunner.StopAndCleanupAllDefaultSchedulers(); Cleanup(); }
public IEnumerator ParallelMultiThread() { yield return(null); var parallelMultiThread = new MultiThreadedParallelTaskCollection("test", 2, true); parallelMultiThread.Add(new SlowTask()); parallelMultiThread.Add(new SlowTask()); var sw = System.Diagnostics.Stopwatch.StartNew(); parallelMultiThread.Complete(); parallelMultiThread.Dispose(); sw.Stop(); Assert.That(sw.ElapsedMilliseconds, Is.AtLeast(900)); Assert.That(sw.ElapsedMilliseconds, Is.AtMost(1100)); }
public IEnumerator TestMultiThreadParallelTaskCompletes() { yield return(null); var test = new MultiThreadedParallelTaskCollection("test", 4, false); bool done = false; test.onComplete += () => done = true; Token token = new Token(); test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); var multiThreadRunner = new MultiThreadRunner("test", true); test.RunOnScheduler(multiThreadRunner); DateTime now = DateTime.Now; yield return(null); while (test.isRunning) { yield return(null); } var totalSeconds = (DateTime.Now - now).TotalSeconds; Assert.Greater(totalSeconds, 1.9); Assert.Less(totalSeconds, 2.1); Assert.That(done, Is.True); Assert.AreEqual(4, token.count); test.Dispose(); multiThreadRunner.Dispose(); }
public IEnumerator TestStopMultiThreadParallelTask() { var test = new MultiThreadedParallelTaskCollection("test", 4, false); Token token = new Token(); bool done = false; test.onComplete += () => done = true; test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); test.Add(new WaitEnumerator(token)); test.Run(); yield return(new WaitForSeconds(0.5f)); test.Stop(); test.Dispose(); Assert.That(done, Is.False); Assert.AreEqual(token.count, 0); }