File tree Expand file tree Collapse file tree 3 files changed +32
-12
lines changed
Expand file tree Collapse file tree 3 files changed +32
-12
lines changed Original file line number Diff line number Diff line change 11using NUnit . Framework ;
2- using System ;
32using System . Runtime . InteropServices ;
4- using System . Threading ;
53
64namespace 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}
Original file line number Diff line number Diff line change 11using NUnit . Framework ;
2+ using System . Runtime . InteropServices ;
23
34namespace 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}
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments