From 750403de7601b0bee278db804490bb220f6d735b Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Wed, 29 Nov 2023 15:45:30 -0500 Subject: [PATCH] Update `world.time` in DMTests --- Content.Tests/DMTests.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Content.Tests/DMTests.cs b/Content.Tests/DMTests.cs index 72c62cf5416..4d9d4a99aac 100644 --- a/Content.Tests/DMTests.cs +++ b/Content.Tests/DMTests.cs @@ -31,6 +31,7 @@ public sealed class DMTests : ContentUnitTest { [Dependency] private readonly DreamObjectTree _objectTree = default!; [Dependency] private readonly ProcScheduler _procScheduler = default!; [Dependency] private readonly ITaskManager _taskManager = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; [Flags] public enum DMTestFlags { @@ -87,6 +88,8 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) { Assert.IsTrue(compiledFile is not null && File.Exists(compiledFile), "Failed to compile DM source file"); Assert.IsTrue(_dreamMan.LoadJson(compiledFile), $"Failed to load {compiledFile}"); + + _gameTiming.CurTick = new(1); _dreamMan.StartWorld(); (bool successfulRun, DreamValue? returned, Exception? exception) = RunTest(); @@ -136,17 +139,17 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags) { } }); - var watch = new Stopwatch(); - watch.Start(); - + var totalTicks = 0; // Tick until our inner call has finished while (!callTask.IsCompleted || _procScheduler.HasProcsQueued || _procScheduler.HasProcsSleeping) { + if (++totalTicks > 100000) { + Assert.Fail("Test ran for too many ticks!"); + } + _dreamMan.Update(); _taskManager.ProcessPendingTasks(); - if (watch.Elapsed.TotalSeconds > 5) { - Assert.Fail("Test timed out"); - } + _gameTiming.CurTick += 1; } bool retSuccess = _dreamMan.LastDMException == prev; // Works because "null == null" is true in this language.