Skip to content

Commit 59ce805

Browse files
authored
test: implement test for NetworkUpdateLoop injecting NetworkUpdateStages into the PlayerLoop (#554)
* initial wip * implement networkupdatestage injection test
1 parent 5187de6 commit 59ce805

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

com.unity.multiplayer.mlapi/Runtime/Core/NetworkUpdateLoop.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private static void RunNetworkUpdateStage(NetworkUpdateStage updateStage)
150150
}
151151
}
152152

153-
private struct NetworkInitialization
153+
internal struct NetworkInitialization
154154
{
155155
public static PlayerLoopSystem CreateLoopSystem()
156156
{
@@ -162,7 +162,7 @@ public static PlayerLoopSystem CreateLoopSystem()
162162
}
163163
}
164164

165-
private struct NetworkEarlyUpdate
165+
internal struct NetworkEarlyUpdate
166166
{
167167
public static PlayerLoopSystem CreateLoopSystem()
168168
{
@@ -174,7 +174,7 @@ public static PlayerLoopSystem CreateLoopSystem()
174174
}
175175
}
176176

177-
private struct NetworkFixedUpdate
177+
internal struct NetworkFixedUpdate
178178
{
179179
public static PlayerLoopSystem CreateLoopSystem()
180180
{
@@ -186,7 +186,7 @@ public static PlayerLoopSystem CreateLoopSystem()
186186
}
187187
}
188188

189-
private struct NetworkPreUpdate
189+
internal struct NetworkPreUpdate
190190
{
191191
public static PlayerLoopSystem CreateLoopSystem()
192192
{
@@ -198,7 +198,7 @@ public static PlayerLoopSystem CreateLoopSystem()
198198
}
199199
}
200200

201-
private struct NetworkUpdate
201+
internal struct NetworkUpdate
202202
{
203203
public static PlayerLoopSystem CreateLoopSystem()
204204
{
@@ -210,7 +210,7 @@ public static PlayerLoopSystem CreateLoopSystem()
210210
}
211211
}
212212

213-
private struct NetworkPreLateUpdate
213+
internal struct NetworkPreLateUpdate
214214
{
215215
public static PlayerLoopSystem CreateLoopSystem()
216216
{
@@ -222,7 +222,7 @@ public static PlayerLoopSystem CreateLoopSystem()
222222
}
223223
}
224224

225-
private struct NetworkPostLateUpdate
225+
internal struct NetworkPostLateUpdate
226226
{
227227
public static PlayerLoopSystem CreateLoopSystem()
228228
{
@@ -361,4 +361,4 @@ private static void Initialize()
361361
PlayerLoop.SetPlayerLoop(customPlayerLoop);
362362
}
363363
}
364-
}
364+
}

com.unity.multiplayer.mlapi/Tests/Runtime/NetworkUpdateLoopTests.cs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,70 @@
11
using System;
22
using System.Collections;
3+
using System.Linq;
34
using UnityEngine;
45
using UnityEngine.TestTools;
56
using NUnit.Framework;
7+
using UnityEngine.LowLevel;
8+
using UnityEngine.PlayerLoop;
69

710
namespace MLAPI.RuntimeTests
811
{
912
public class NetworkUpdateLoopTests
1013
{
14+
[Test]
15+
public void UpdateStageInjection()
16+
{
17+
var currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop();
18+
for (int i = 0; i < currentPlayerLoop.subSystemList.Length; i++)
19+
{
20+
var playerLoopSystem = currentPlayerLoop.subSystemList[i];
21+
var subsystems = playerLoopSystem.subSystemList.ToList();
22+
23+
if (playerLoopSystem.type == typeof(Initialization))
24+
{
25+
Assert.True(
26+
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkInitialization)),
27+
nameof(NetworkUpdateLoop.NetworkInitialization));
28+
}
29+
else if (playerLoopSystem.type == typeof(EarlyUpdate))
30+
{
31+
Assert.True(
32+
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkEarlyUpdate)),
33+
nameof(NetworkUpdateLoop.NetworkEarlyUpdate));
34+
}
35+
else if (playerLoopSystem.type == typeof(FixedUpdate))
36+
{
37+
Assert.True(
38+
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkFixedUpdate)),
39+
nameof(NetworkUpdateLoop.NetworkFixedUpdate));
40+
}
41+
else if (playerLoopSystem.type == typeof(PreUpdate))
42+
{
43+
Assert.True(
44+
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkPreUpdate)),
45+
nameof(NetworkUpdateLoop.NetworkPreUpdate));
46+
}
47+
else if (playerLoopSystem.type == typeof(Update))
48+
{
49+
Assert.True(
50+
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkUpdate)),
51+
nameof(NetworkUpdateLoop.NetworkUpdate));
52+
}
53+
else if (playerLoopSystem.type == typeof(PreLateUpdate))
54+
{
55+
Assert.True(
56+
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkPreLateUpdate)),
57+
nameof(NetworkUpdateLoop.NetworkPreLateUpdate));
58+
}
59+
else if (playerLoopSystem.type == typeof(PostLateUpdate))
60+
{
61+
Assert.True(
62+
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkPostLateUpdate)),
63+
nameof(NetworkUpdateLoop.NetworkPostLateUpdate));
64+
}
65+
}
66+
}
67+
1168
private struct NetworkUpdateCallbacks
1269
{
1370
public Action OnInitialization;
@@ -292,4 +349,4 @@ public IEnumerator UpdateStagesMixed()
292349
}
293350
}
294351
}
295-
}
352+
}

0 commit comments

Comments
 (0)