Skip to content

Commit

Permalink
Amend EnsureInitialised init variable
Browse files Browse the repository at this point in the history
  • Loading branch information
SignatureBeef committed Jan 4, 2025
1 parent c6a85aa commit 123f37c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions TerrariaServerAPI.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using NUnit.Framework;
using System.Runtime.InteropServices;
using Terraria.Utilities;

namespace TerrariaServerAPI.Tests;

Expand All @@ -11,27 +10,28 @@ public class BaseTest
[OneTimeSetUp]
public void EnsureInitialised()
{
TestContext.Out.WriteLine($"Test architecture {RuntimeInformation.ProcessArchitecture}");

if (!_initialized)
{
TestContext.Out.WriteLine($"Test architecture {RuntimeInformation.ProcessArchitecture}");

bool invoked = false;
HookEvents.HookDelegate<global::Terraria.Main, HookEvents.Terraria.Main.DedServEventArgs> cb = (instance, args) =>
HookEvents.HookDelegate<Terraria.Main, HookEvents.Terraria.Main.DedServEventArgs> cb = (instance, args) =>
{
invoked = true;
// DedServ typically requires input, so no need to continue execution
args.ContinueExecution = false;
// DedServ calls the following, which is needed for subsequent tests
global::Terraria.Main.rand = new UnifiedRandom();
instance.Initialize();
};
HookEvents.Terraria.Main.DedServ += cb;

global::TerrariaApi.Server.Program.Main([]);
TerrariaApi.Server.Program.Main([]);

HookEvents.Terraria.Main.DedServ -= cb;

Assert.That(invoked, Is.True);

_initialized = true;
}
}
}
12 changes: 4 additions & 8 deletions TerrariaServerAPI.Tests/ServerInitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ public void EnsureRuntimeDetours()

bool invoked = false;

On.Terraria.Main.hook_DedServ callback = (orig, self) =>
{
invoked = true;
// DedServ typically requires input, so no need to continue execution
};
On.Terraria.Main.DedServ += callback;
On.Terraria.Program.hook_RunGame callback = (orig) => invoked = true;
On.Terraria.Program.RunGame += callback;

global::TerrariaApi.Server.Program.Main([]);
Terraria.Program.RunGame();

On.Terraria.Main.DedServ -= callback;
On.Terraria.Program.RunGame -= callback;

Assert.That(invoked, Is.True);
}
Expand Down

0 comments on commit 123f37c

Please sign in to comment.