Skip to content

Commit a360e12

Browse files
committed
OTAPI update for MMRD 25.x + test to confirm
Excluding ARM64 as expected to currently fail / not supported
1 parent 38d4276 commit a360e12

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using NUnit.Framework;
2-
using System;
32
using System.Runtime.InteropServices;
4-
using System.Threading;
53

64
namespace TerrariaServerAPI.Tests;
75

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

1715
if (!_initialized)
1816
{
19-
AutoResetEvent are = new(false);
20-
Exception? error = null;
17+
bool invoked = false;
2118
HookEvents.HookDelegate<global::Terraria.Main, HookEvents.Terraria.Main.DedServEventArgs> cb = (instance, args) =>
2219
{
23-
instance.Initialize();
24-
are.Set();
25-
_initialized = true;
20+
invoked = true;
21+
// DedServ typically requires input, so no need to continue execution
22+
args.ContinueExecution = false;
2623
};
2724
HookEvents.Terraria.Main.DedServ += cb;
2825

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

31-
_initialized = are.WaitOne(TimeSpan.FromSeconds(30));
32-
3328
HookEvents.Terraria.Main.DedServ -= cb;
3429

35-
Assert.That(_initialized, Is.True);
36-
Assert.That(error, Is.Null);
30+
Assert.That(invoked, Is.True);
3731
}
3832
}
3933
}

TerrariaServerAPI.Tests/ServerInitTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using System.Runtime.InteropServices;
23

34
namespace TerrariaServerAPI.Tests;
45

@@ -9,4 +10,29 @@ public void EnsureBoots()
910
{
1011
EnsureInitialised();
1112
}
13+
14+
[Test]
15+
public void EnsureRuntimeDetours()
16+
{
17+
// Platform exclude doesnt support arm64, so manual check it is...
18+
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
19+
Assert.Ignore("Test is not supported on ARM64 architecture.");
20+
21+
TestContext.Out.WriteLine($"Test architecture {RuntimeInformation.ProcessArchitecture}");
22+
23+
bool invoked = false;
24+
25+
On.Terraria.Main.hook_DedServ callback = (orig, self) =>
26+
{
27+
invoked = true;
28+
// DedServ typically requires input, so no need to continue execution
29+
};
30+
On.Terraria.Main.DedServ += callback;
31+
32+
global::TerrariaApi.Server.Program.Main([]);
33+
34+
On.Terraria.Main.DedServ -= callback;
35+
36+
Assert.That(invoked, Is.True);
37+
}
1238
}

TerrariaServerAPI/TerrariaServerAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
<ItemGroup>
2424
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2525
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="9.0.0" />
26-
<PackageReference Include="OTAPI.Upcoming" Version="3.2.2" />
26+
<PackageReference Include="OTAPI.Upcoming" Version="3.2.3" />
2727
</ItemGroup>
2828
</Project>

0 commit comments

Comments
 (0)