-
Notifications
You must be signed in to change notification settings - Fork 461
test: add RpcQueue unit tests #521
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
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1b47985
test: RPC Queue tests
NoelStephensUnity c53c92d
test: refactoring additional test against each rpc update stage
NoelStephensUnity e927fbf
fix: removing interface
NoelStephensUnity bdb5121
Merge branch 'develop' into test/rpcqueue
NoelStephensUnity a885208
refactor and style: fixed some minor issues and standards update
NoelStephensUnity 59c4ce4
style: removing function names and CamelCase
NoelStephensUnity ebfa3de
style: standards
NoelStephensUnity 33ba943
style: standards
NoelStephensUnity be9d583
fix: bug with standards change
NoelStephensUnity 778bff0
style: standards
NoelStephensUnity 6f7052b
style: standards local vars
NoelStephensUnity fc83b30
refactor: stopping host and shutting down
NoelStephensUnity 31c8f67
fix: Unity Editor define
NoelStephensUnity 0c1b652
Including
NoelStephensUnity 1e7b249
refactor and style
NoelStephensUnity 97d39dc
refactor
NoelStephensUnity f2037c4
refactor
NoelStephensUnity 4c5865f
refactor
NoelStephensUnity f6ec480
refactor
NoelStephensUnity f2c8edc
refactor
NoelStephensUnity 1679159
refactor
NoelStephensUnity f480e2f
Merge branch 'develop' into test/rpcqueue
NoelStephensUnity a8c3694
fix and refactor rpcqueuetests
0xFA11 337e362
Merge branch 'develop' into test/rpcqueue
0xFA11 d6288d0
fix compile errors after merging develop branch
0xFA11 6739912
set server/client receive params' updatestage fields to initializatio…
0xFA11 8d3415e
add unitysetup and unityteardown steps into rpcqueuetests
0xFA11 28926d3
destroy gameobjects created during the test
0xFA11 42ecad0
if-guard around unitysetup and unityteardown
0xFA11 cd4df27
try more stuff
0xFA11 68952ee
revert asmdef changes
0xFA11 e3c38c2
revert proejctsettings change
0xFA11 bb40fd9
disable rpcqueuetests on 2019.4 (due to ILPP issues)
0xFA11 f345b9a
comment why we disabled RpcQueueUnitTest
0xFA11 cd2ac3e
Merge branch 'develop' into test/rpcqueue
0xFA11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
com.unity.multiplayer.mlapi/Tests/Runtime/RPCQueueTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| using System.Collections; | ||
| using NUnit.Framework; | ||
| using UnityEngine; | ||
| using UnityEngine.SceneManagement; | ||
| using UnityEngine.TestTools; | ||
| using MLAPI.SceneManagement; | ||
| using MLAPI.Transports.UNET; | ||
|
|
||
| namespace MLAPI.RuntimeTests | ||
| { | ||
| public class RPCQueueTests | ||
| { | ||
| private NetworkingManager m_NetMan; | ||
|
|
||
| [UnitySetUp] | ||
| public IEnumerator SetUp() | ||
| { | ||
| yield return new EnterPlayMode(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// RPCQueueUnitTest | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
| /// Tests the egress and ingress RPC queue functionality | ||
| /// ** This does not include any of the MLAPI to Transport code ** | ||
| /// </summary> | ||
| /// <returns>IEnumerator</returns> | ||
| [UnityTest] | ||
| public IEnumerator RPCQueueUnitTest() | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
| { | ||
| var NetManObject = new GameObject(); | ||
| m_NetMan = NetManObject.AddComponent<NetworkingManager>(); | ||
| UnetTransport unetTransport = NetManObject.AddComponent<UnetTransport>(); | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
| m_NetMan.NetworkConfig = new Configuration.NetworkConfig(); | ||
| m_NetMan.NetworkConfig.CreatePlayerPrefab = false; | ||
| m_NetMan.NetworkConfig.AllowRuntimeSceneChanges = true; | ||
| m_NetMan.NetworkConfig.EnableSceneManagement = false; | ||
| unetTransport.ConnectAddress = "127.0.0.1"; | ||
| unetTransport.ConnectPort = 7777; | ||
| unetTransport.ServerListenPort = 7777; | ||
| unetTransport.MessageBufferSize = 65535; | ||
| unetTransport.MaxConnections = 100; | ||
| unetTransport.MessageSendMode = UnetTransport.SendMode.Immediately; | ||
| m_NetMan.NetworkConfig.NetworkTransport = unetTransport; | ||
|
|
||
| var CurrentActiveScene = SceneManager.GetActiveScene(); | ||
| var InstantiatedNetworkingManager = false; | ||
| var TestsAreComplete = false; | ||
| var TestsAreValidated = false; | ||
| var MaximumTimeTaken = 0.0f; | ||
|
|
||
| if (CurrentActiveScene != null) | ||
| { | ||
| //Add our test scene name | ||
| NetworkSceneManager.AddRuntimeSceneName(CurrentActiveScene.name, 0); | ||
|
|
||
| //Create the player object that we will spawn as a host | ||
| GameObject playerObject = new GameObject("RpcTestObject"); | ||
| NetworkedObject playerNetworkObject = playerObject.AddComponent<NetworkedObject>(); | ||
| RpcPipelineTestComponent RpcPipelineTestComponent = playerObject.AddComponent<RpcPipelineTestComponent>(); | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (NetworkingManager.Singleton != null) | ||
| { | ||
| Debug.Log("Networking Manager Instantiated."); | ||
| InstantiatedNetworkingManager = true; | ||
| //Start as host mode as loopback only works in hostmode | ||
| NetworkingManager.Singleton.StartHost(); | ||
|
|
||
| Debug.Log("Host Started."); | ||
|
|
||
| if (RpcPipelineTestComponent != null) | ||
| { | ||
| //Enable the simple ping test | ||
| RpcPipelineTestComponent.PingSelfEnabled = true; | ||
| Debug.Log("Running RPC Queue Tests..."); | ||
|
|
||
| //We shouldn't (for sure) take longer than 30 seconds | ||
| MaximumTimeTaken = Time.realtimeSinceStartup + 30.0f; | ||
|
|
||
| //Wait for the rpc pipeline test to complete or | ||
| while (!TestsAreComplete && MaximumTimeTaken > Time.realtimeSinceStartup) | ||
| { | ||
| //Wait for 100ms | ||
| yield return new WaitForSeconds(0.1f); | ||
|
|
||
| TestsAreComplete = RpcPipelineTestComponent.IsTestComplete(); | ||
| } | ||
|
|
||
| TestsAreValidated = RpcPipelineTestComponent.ValidateUpdateStages(); | ||
| //Stop pinging | ||
| RpcPipelineTestComponent.PingSelfEnabled = false; | ||
|
|
||
| Debug.Log("RPC Queue Testing completed."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Assert.IsTrue(TestsAreComplete && TestsAreValidated && InstantiatedNetworkingManager && MaximumTimeTaken > Time.realtimeSinceStartup); | ||
| // Use the Assert class to test conditions. | ||
| // Use yield to skip a frame. | ||
| yield return null; | ||
| } | ||
|
|
||
|
|
||
| [UnitySetUp] | ||
| public IEnumerator TearDown() | ||
| { | ||
| yield return new ExitPlayMode(); | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
com.unity.multiplayer.mlapi/Tests/Runtime/RPCQueueTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
176 changes: 176 additions & 0 deletions
176
com.unity.multiplayer.mlapi/Tests/Runtime/RpcPipelineTestComponent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using MLAPI; | ||
| using MLAPI.Messaging; | ||
|
|
||
| namespace MLAPI.RuntimeTests | ||
| { | ||
| public class RpcPipelineTestComponent : NetworkedBehaviour | ||
| { | ||
| /// <summary> | ||
| /// PingSelfEnabled | ||
| /// Allows the external RPCQueueTest to begin testing or stop it | ||
| /// </summary> | ||
| public bool PingSelfEnabled; | ||
|
|
||
| /// <summary> | ||
| /// MaxIterations | ||
| /// How many times will we iterate through the various NetworkUpdateStage values? | ||
| /// (defaults to 2) | ||
| /// </summary> | ||
| public int MaxIterations = 2; | ||
|
|
||
|
|
||
| // Start is called before the first frame update | ||
| void Start() | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
| { | ||
| m_Serverparms.Send.UpdateStage = NetworkUpdateStage.Initialization; | ||
| m_Clientparms.Send.UpdateStage = NetworkUpdateStage.Update; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// IsTestComplete | ||
| /// Returns back whether the test has completed the total number of iterations | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public bool IsTestComplete() | ||
| { | ||
| if (m_Counter >= MaxIterations) | ||
| { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private int m_Counter = 0; | ||
| private float m_NextUpdate = 0.0f; | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
| private ServerRpcParams m_Serverparms; | ||
| private ClientRpcParams m_Clientparms; | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
| private NetworkUpdateStage m_LastUpdateStage; | ||
|
|
||
| // Update is called once per frame | ||
| void Update() | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
| { | ||
| if (NetworkingManager.Singleton.IsListening && PingSelfEnabled && m_NextUpdate < Time.realtimeSinceStartup) | ||
| { | ||
| if (NetworkingManager.Singleton.IsListening && PingSelfEnabled && m_NextUpdate < Time.realtimeSinceStartup) | ||
| { | ||
| //As long as testing isn't completed, keep testing | ||
| if (!IsTestComplete()) | ||
| { | ||
| m_NextUpdate = Time.realtimeSinceStartup + 0.5f; | ||
| m_LastUpdateStage = m_Serverparms.Send.UpdateStage; | ||
| m_StagesSent.Add(m_LastUpdateStage); | ||
| PingMySelfServerRPC(m_Serverparms); | ||
| m_Clientparms.Send.UpdateStage = m_Serverparms.Send.UpdateStage; | ||
| switch (m_Serverparms.Send.UpdateStage) | ||
| { | ||
| case NetworkUpdateStage.Initialization: | ||
| { | ||
| m_Serverparms.Send.UpdateStage = NetworkUpdateStage.EarlyUpdate; | ||
| break; | ||
| } | ||
| case NetworkUpdateStage.EarlyUpdate: | ||
| { | ||
| m_Serverparms.Send.UpdateStage = NetworkUpdateStage.FixedUpdate; | ||
| break; | ||
| } | ||
| case NetworkUpdateStage.FixedUpdate: | ||
| { | ||
| m_Serverparms.Send.UpdateStage = NetworkUpdateStage.PreUpdate; | ||
| break; | ||
| } | ||
| case NetworkUpdateStage.PreUpdate: | ||
| { | ||
| m_Serverparms.Send.UpdateStage = NetworkUpdateStage.Update; | ||
| break; | ||
| } | ||
| case NetworkUpdateStage.Update: | ||
| { | ||
| m_Serverparms.Send.UpdateStage = NetworkUpdateStage.PreLateUpdate; | ||
| break; | ||
| } | ||
| case NetworkUpdateStage.PreLateUpdate: | ||
| { | ||
| m_Serverparms.Send.UpdateStage = NetworkUpdateStage.PostLateUpdate; | ||
| break; | ||
| } | ||
| case NetworkUpdateStage.PostLateUpdate: | ||
| { | ||
| m_Serverparms.Send.UpdateStage = NetworkUpdateStage.Initialization; | ||
|
|
||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private List<NetworkUpdateStage> m_ServerStagesReceived = new List<NetworkUpdateStage>(); | ||
| private List<NetworkUpdateStage> m_ClientStagesReceived = new List<NetworkUpdateStage>(); | ||
| private List<NetworkUpdateStage> m_StagesSent = new List<NetworkUpdateStage>(); | ||
|
|
||
| /// <summary> | ||
| /// ValidateUpdateStages | ||
| /// Assures all update stages were in alginment with one another | ||
| /// </summary> | ||
| /// <returns>true or false</returns> | ||
| public bool ValidateUpdateStages() | ||
| { | ||
| var Validated = false; | ||
| if (m_ServerStagesReceived.Count == m_ClientStagesReceived.Count && m_ClientStagesReceived.Count == m_StagesSent.Count) | ||
| { | ||
| for (int i = 0; i < m_StagesSent.Count; i++) | ||
| { | ||
| NetworkUpdateStage currentStage = m_StagesSent[i]; | ||
| if (m_ServerStagesReceived[i] != currentStage) | ||
| { | ||
| Debug.LogFormat("ServerRpc Update Stage ( {0} ) is not equal to the current update stage ( {1} ) ", m_ServerStagesReceived[i].ToString(), currentStage.ToString()); | ||
| return Validated; | ||
| } | ||
| if (m_ClientStagesReceived[i] != currentStage) | ||
| { | ||
| Debug.LogFormat("ClientRpc Update Stage ( {0} ) is not equal to the current update stage ( {1} ) ", m_ClientStagesReceived[i].ToString(), currentStage.ToString()); | ||
| return Validated; | ||
| } | ||
| } | ||
| Validated = true; | ||
| } | ||
| return Validated; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// PingMySelfServerRPC | ||
| /// Server side RPC for testing | ||
| /// </summary> | ||
| /// <param name="parameters">server rpc parameters</param> | ||
| [ServerRpc] | ||
| void PingMySelfServerRPC(ServerRpcParams parameters) | ||
| { | ||
| Debug.Log("[HostClient][ServerRpc] invoked during the " + parameters.Receive.UpdateStage.ToString() + " stage."); | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
| m_Clientparms.Send.UpdateStage = parameters.Receive.UpdateStage; | ||
| m_ServerStagesReceived.Add(m_Clientparms.Send.UpdateStage); | ||
| PingMySelfClientRpc(m_Clientparms); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// PingMySelfClientRpc | ||
| /// Client Side RPC called by PingMySelfServerRPC to validate both Client->Server and Server-Client pipeline is working | ||
| /// </summary> | ||
| /// <param name="parameters">client rpc parameters</param> | ||
| [ClientRpc] | ||
| void PingMySelfClientRpc(ClientRpcParams parameters) | ||
| { | ||
| m_ClientStagesReceived.Add(m_Clientparms.Send.UpdateStage); | ||
| Debug.Log("[HostServer][ClientRpc] invoked during the " + parameters.Receive.UpdateStage.ToString() + " stage. (previous output line should confirm this)"); | ||
|
NoelStephensUnity marked this conversation as resolved.
Outdated
|
||
|
|
||
| //If we reached the last update state, then go ahead and increment our iteration counter | ||
| if (parameters.Receive.UpdateStage == NetworkUpdateStage.PostLateUpdate) | ||
| { | ||
| m_Counter++; | ||
| } | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
com.unity.multiplayer.mlapi/Tests/Runtime/RpcPipelineTestComponent.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.