From 0911a5e454cf11958d1654adbde6c57c41f7a132 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sun, 26 Nov 2023 21:53:56 -0500 Subject: [PATCH] Fix ProcScheduler state poisoning between tests --- Content.Tests/DMTests.cs | 4 +++- OpenDreamRuntime/Procs/ProcScheduler.Delays.cs | 2 ++ OpenDreamRuntime/Procs/ProcScheduler.cs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Content.Tests/DMTests.cs b/Content.Tests/DMTests.cs index 59b69dde28..8fb03bf6bc 100644 --- a/Content.Tests/DMTests.cs +++ b/Content.Tests/DMTests.cs @@ -5,6 +5,7 @@ using NUnit.Framework; using OpenDreamRuntime; using OpenDreamRuntime.Objects; +using OpenDreamRuntime.Procs; using OpenDreamRuntime.Rendering; using OpenDreamShared.Rendering; using Robust.Shared.Asynchronous; @@ -28,6 +29,7 @@ public sealed class DMTests : ContentUnitTest { [Dependency] private readonly DreamManager _dreamMan = default!; [Dependency] private readonly DreamObjectTree _objectTree = default!; + [Dependency] private readonly ProcScheduler _procScheduler = default!; [Dependency] private readonly ITaskManager _taskManager = default!; [Flags] @@ -138,7 +140,7 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) { watch.Start(); // Tick until our inner call has finished - while (!callTask.IsCompleted) { + while (!callTask.IsCompleted || _procScheduler.HasProcsQueued || _procScheduler.HasProcsSleeping) { _dreamMan.Update(); _taskManager.ProcessPendingTasks(); diff --git a/OpenDreamRuntime/Procs/ProcScheduler.Delays.cs b/OpenDreamRuntime/Procs/ProcScheduler.Delays.cs index 71339b2010..fa2727d165 100644 --- a/OpenDreamRuntime/Procs/ProcScheduler.Delays.cs +++ b/OpenDreamRuntime/Procs/ProcScheduler.Delays.cs @@ -14,6 +14,8 @@ public sealed partial class ProcScheduler { // This is for deferred tasks that need to fire in the current tick. private readonly Queue _deferredTasks = new(); + public bool HasProcsSleeping => _tickers.Count > 0; + /// /// Create a task that will delay by an amount of time, following the rules for sleep and spawn. /// diff --git a/OpenDreamRuntime/Procs/ProcScheduler.cs b/OpenDreamRuntime/Procs/ProcScheduler.cs index 998a291dad..2daee6f2a9 100644 --- a/OpenDreamRuntime/Procs/ProcScheduler.cs +++ b/OpenDreamRuntime/Procs/ProcScheduler.cs @@ -26,7 +26,7 @@ public sealed partial class ProcScheduler { private readonly Queue _scheduled = new(); private AsyncNativeProc.State? _current; - bool HasProcsQueued => _scheduled.Count > 0 || _deferredTasks.Count > 0; + public bool HasProcsQueued => _scheduled.Count > 0 || _deferredTasks.Count > 0; public Task Schedule(AsyncNativeProc.State state, Func> taskFunc) { async Task Foo() {