Skip to content

Commit

Permalink
Clear ProcScheduler state each test run
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Feb 9, 2024
1 parent 8c66a1d commit 1e4dd81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Content.Tests/DMTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions OpenDreamRuntime/Procs/ProcScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public void Process() {
}
}

/// <summary>
/// Clears all ProcScheduler state
/// </summary>
public void ClearState() {
_current = null;
_deferredTasks.Clear();
_sleeping.Clear();
_scheduled.Clear();
_tickers.Clear();
}

public IEnumerable<DreamThread> InspectThreads() {
// TODO: We shouldn't need to check if Thread is null here
// I think we're keeping disposed states somewhere here
Expand Down

0 comments on commit 1e4dd81

Please sign in to comment.