Skip to content

Commit 44cfa29

Browse files
authored
test: implement extra features on top of existing NetworkUpdateLoopTests to cover other test cases (#559)
* implement extra features on top of existing tests to cover other test cases too * minor update
1 parent 3b0c29d commit 44cfa29

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ private void Awake()
224224
this.RegisterNetworkUpdate(NetworkUpdateStage.FixedUpdate);
225225
this.RegisterNetworkUpdate(NetworkUpdateStage.PreUpdate);
226226
this.RegisterNetworkUpdate(NetworkUpdateStage.PreLateUpdate);
227+
this.RegisterNetworkUpdate(NetworkUpdateStage.PostLateUpdate);
228+
229+
// intentionally try to register for 'PreUpdate' stage twice
230+
// it should be ignored and the instance should not be registered twice
231+
// otherwise test would fail because it would call 'OnPreUpdate()' twice
232+
// which would ultimately increment 'netUpdates[idx]' integer twice
233+
// and cause 'Assert.AreEqual()' to fail the test
234+
this.RegisterNetworkUpdate(NetworkUpdateStage.PreUpdate);
227235
}
228236

229237
public void NetworkUpdate(NetworkUpdateStage updateStage)
@@ -239,6 +247,9 @@ public void NetworkUpdate(NetworkUpdateStage updateStage)
239247
case NetworkUpdateStage.PreLateUpdate:
240248
UpdateCallbacks.OnPreLateUpdate();
241249
break;
250+
case NetworkUpdateStage.PostLateUpdate:
251+
UpdateCallbacks.OnPostLateUpdate();
252+
break;
242253
}
243254
}
244255

@@ -269,7 +280,8 @@ public IEnumerator UpdateStagesMixed()
269280
const int kNetFixedUpdateIndex = 0;
270281
const int kNetPreUpdateIndex = 1;
271282
const int kNetPreLateUpdateIndex = 2;
272-
int[] netUpdates = new int[3];
283+
const int kNetPostLateUpdateIndex = 3;
284+
int[] netUpdates = new int[4];
273285
const int kMonoFixedUpdateIndex = 0;
274286
const int kMonoUpdateIndex = 1;
275287
const int kMonoLateUpdateIndex = 2;
@@ -304,6 +316,14 @@ public IEnumerator UpdateStagesMixed()
304316
netUpdates[kNetPreLateUpdateIndex]++;
305317
Assert.AreEqual(monoUpdates[kMonoLateUpdateIndex] + 1, netUpdates[kNetPreLateUpdateIndex]);
306318
}
319+
},
320+
OnPostLateUpdate = () =>
321+
{
322+
if (isTesting)
323+
{
324+
netUpdates[kNetPostLateUpdateIndex]++;
325+
Assert.AreEqual(netUpdates[kNetPostLateUpdateIndex], netUpdates[kNetPreLateUpdateIndex]);
326+
}
307327
}
308328
};
309329
gameScript.BehaviourCallbacks = new MonoBehaviourCallbacks

0 commit comments

Comments
 (0)