diff --git a/Content.Tests/DMTests.cs b/Content.Tests/DMTests.cs index 961c5305bd..079b1188b1 100644 --- a/Content.Tests/DMTests.cs +++ b/Content.Tests/DMTests.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Threading.Tasks; using NUnit.Framework; using OpenDreamRuntime; using OpenDreamRuntime.Objects; using OpenDreamRuntime.Procs; -using OpenDreamRuntime.Rendering; -using OpenDreamShared.Rendering; using Robust.Shared.Asynchronous; using Robust.Shared.IoC; using Robust.Shared.Timing; @@ -74,6 +73,8 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) { return; } + _procScheduler.ClearState(); + Assert.That(compiledFile is not null && File.Exists(compiledFile), "Failed to compile DM source file"); Assert.That(_dreamMan.LoadJson(compiledFile), $"Failed to load {compiledFile}"); _dreamMan.StartWorld(); @@ -99,6 +100,9 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) { Assert.That(returned?.IsTruthy(), Is.True, "Test was expected to return TRUE"); } + var threads = _procScheduler.InspectThreads().ToList(); + Assert.That(threads.Count == 0 && !_procScheduler.HasProcsSleeping && !_procScheduler.HasProcsQueued, $"One or more threads did not finish!"); + Cleanup(compiledFile); TestContext.WriteLine($"--- PASS {sourceFile}"); } finally { diff --git a/OpenDreamRuntime/Procs/ProcScheduler.cs b/OpenDreamRuntime/Procs/ProcScheduler.cs index 5c1f39d439..f3f773a37d 100644 --- a/OpenDreamRuntime/Procs/ProcScheduler.cs +++ b/OpenDreamRuntime/Procs/ProcScheduler.cs @@ -74,6 +74,17 @@ public void Process() { } } + /// + /// Clears all ProcScheduler state + /// + public void ClearState() { + _current = null; + _deferredTasks.Clear(); + _sleeping.Clear(); + _scheduled.Clear(); + _tickers.Clear(); + } + public IEnumerable InspectThreads() { // TODO: We shouldn't need to check if Thread is null here // I think we're keeping disposed states somewhere here