Skip to content

test: implement test for NetworkUpdateLoop injecting NetworkUpdateStages into the PlayerLoop #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkUpdateLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static void RunNetworkUpdateStage(NetworkUpdateStage updateStage)
}
}

private struct NetworkInitialization
internal struct NetworkInitialization
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -162,7 +162,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkEarlyUpdate
internal struct NetworkEarlyUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -174,7 +174,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkFixedUpdate
internal struct NetworkFixedUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -186,7 +186,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkPreUpdate
internal struct NetworkPreUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -198,7 +198,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkUpdate
internal struct NetworkUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -210,7 +210,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkPreLateUpdate
internal struct NetworkPreLateUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand All @@ -222,7 +222,7 @@ public static PlayerLoopSystem CreateLoopSystem()
}
}

private struct NetworkPostLateUpdate
internal struct NetworkPostLateUpdate
{
public static PlayerLoopSystem CreateLoopSystem()
{
Expand Down Expand Up @@ -361,4 +361,4 @@ private static void Initialize()
PlayerLoop.SetPlayerLoop(customPlayerLoop);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,70 @@
using System;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using UnityEngine.LowLevel;
using UnityEngine.PlayerLoop;

namespace MLAPI.RuntimeTests
{
public class NetworkUpdateLoopTests
{
[Test]
public void UpdateStageInjection()
{
var currentPlayerLoop = PlayerLoop.GetCurrentPlayerLoop();
for (int i = 0; i < currentPlayerLoop.subSystemList.Length; i++)
{
var playerLoopSystem = currentPlayerLoop.subSystemList[i];
var subsystems = playerLoopSystem.subSystemList.ToList();

if (playerLoopSystem.type == typeof(Initialization))
{
Assert.True(
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkInitialization)),
nameof(NetworkUpdateLoop.NetworkInitialization));
}
else if (playerLoopSystem.type == typeof(EarlyUpdate))
{
Assert.True(
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkEarlyUpdate)),
nameof(NetworkUpdateLoop.NetworkEarlyUpdate));
}
else if (playerLoopSystem.type == typeof(FixedUpdate))
{
Assert.True(
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkFixedUpdate)),
nameof(NetworkUpdateLoop.NetworkFixedUpdate));
}
else if (playerLoopSystem.type == typeof(PreUpdate))
{
Assert.True(
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkPreUpdate)),
nameof(NetworkUpdateLoop.NetworkPreUpdate));
}
else if (playerLoopSystem.type == typeof(Update))
{
Assert.True(
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkUpdate)),
nameof(NetworkUpdateLoop.NetworkUpdate));
}
else if (playerLoopSystem.type == typeof(PreLateUpdate))
{
Assert.True(
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkPreLateUpdate)),
nameof(NetworkUpdateLoop.NetworkPreLateUpdate));
}
else if (playerLoopSystem.type == typeof(PostLateUpdate))
{
Assert.True(
subsystems.Exists(s => s.type == typeof(NetworkUpdateLoop.NetworkPostLateUpdate)),
nameof(NetworkUpdateLoop.NetworkPostLateUpdate));
}
}
}

private struct NetworkUpdateCallbacks
{
public Action OnInitialization;
Expand Down Expand Up @@ -292,4 +349,4 @@ public IEnumerator UpdateStagesMixed()
}
}
}
}
}