Skip to content

Commit

Permalink
Fix ProcScheduler state poisoning between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Nov 27, 2023
1 parent 4f0b534 commit 0911a5e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Content.Tests/DMTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions OpenDreamRuntime/Procs/ProcScheduler.Delays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskCompletionSource> _deferredTasks = new();

public bool HasProcsSleeping => _tickers.Count > 0;

/// <summary>
/// Create a task that will delay by an amount of time, following the rules for <c>sleep</c> and <c>spawn</c>.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Procs/ProcScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed partial class ProcScheduler {
private readonly Queue<AsyncNativeProc.State> _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<AsyncNativeProc.State, Task<DreamValue>> taskFunc) {
async Task Foo() {
Expand Down

0 comments on commit 0911a5e

Please sign in to comment.