Skip to content

Commit

Permalink
OTAPI update for MMRD 25.x + test to confirm
Browse files Browse the repository at this point in the history
Excluding ARM64 as expected to currently fail / not supported
  • Loading branch information
SignatureBeef committed Jan 4, 2025
1 parent 38d4276 commit a360e12
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
16 changes: 5 additions & 11 deletions TerrariaServerAPI.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using NUnit.Framework;
using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace TerrariaServerAPI.Tests;

Expand All @@ -16,24 +14,20 @@ public void EnsureInitialised()

if (!_initialized)
{
AutoResetEvent are = new(false);
Exception? error = null;
bool invoked = false;
HookEvents.HookDelegate<global::Terraria.Main, HookEvents.Terraria.Main.DedServEventArgs> cb = (instance, args) =>
{
instance.Initialize();
are.Set();
_initialized = true;
invoked = true;
// DedServ typically requires input, so no need to continue execution
args.ContinueExecution = false;
};
HookEvents.Terraria.Main.DedServ += cb;

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

_initialized = are.WaitOne(TimeSpan.FromSeconds(30));

HookEvents.Terraria.Main.DedServ -= cb;

Assert.That(_initialized, Is.True);
Assert.That(error, Is.Null);
Assert.That(invoked, Is.True);
}
}
}
26 changes: 26 additions & 0 deletions TerrariaServerAPI.Tests/ServerInitTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.Runtime.InteropServices;

namespace TerrariaServerAPI.Tests;

Expand All @@ -9,4 +10,29 @@ public void EnsureBoots()
{
EnsureInitialised();
}

[Test]
public void EnsureRuntimeDetours()
{
// Platform exclude doesnt support arm64, so manual check it is...
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
Assert.Ignore("Test is not supported on ARM64 architecture.");

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

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;

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

On.Terraria.Main.DedServ -= callback;

Assert.That(invoked, Is.True);
}
}
2 changes: 1 addition & 1 deletion TerrariaServerAPI/TerrariaServerAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="9.0.0" />
<PackageReference Include="OTAPI.Upcoming" Version="3.2.2" />
<PackageReference Include="OTAPI.Upcoming" Version="3.2.3" />
</ItemGroup>
</Project>

0 comments on commit a360e12

Please sign in to comment.