-
Notifications
You must be signed in to change notification settings - Fork 459
test: update rpc queue unit tests #626
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 all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5f6649b
fix: remove singleton references
NoelStephensUnity 51717d0
test: rpc queue tests
NoelStephensUnity 7275697
Merge branch 'develop' into test/newrpcqueuetests
NoelStephensUnity 95d29d2
fix: Merging Artifact
NoelStephensUnity ea95749
refactor: Better StartNetworkManager parameters
NoelStephensUnity 81093f3
Merge branch 'develop' into test/newrpcqueuetests
NoelStephensUnity 860042e
Update com.unity.multiplayer.mlapi/Tests/Runtime/NetworkManagerHelper.cs
NoelStephensUnity 9d71778
style: static Standards
NoelStephensUnity 224c6c4
Update com.unity.multiplayer.mlapi/Tests/Runtime/NetworkManagerHelper.cs
NoelStephensUnity b6aa98e
style
NoelStephensUnity 33c412e
Merge branch 'test/newrpcqueuetests' of https://github.com/Unity-Tech…
NoelStephensUnity db204d9
Update com.unity.multiplayer.mlapi/Tests/Runtime/NetworkManagerHelper.cs
NoelStephensUnity e2f5646
style: wording
NoelStephensUnity 2548571
Merge branch 'test/newrpcqueuetests' of https://github.com/Unity-Tech…
NoelStephensUnity 84b0010
refactor: debug logs to debug log
NoelStephensUnity 4f81274
Update com.unity.multiplayer.mlapi/Tests/Runtime/RpcQueueTests.cs
NoelStephensUnity 5a1ca8f
Update com.unity.multiplayer.mlapi/Tests/Runtime/RpcQueueTests.cs
NoelStephensUnity fb0f45b
Update com.unity.multiplayer.mlapi/Tests/Runtime/RpcQueueTests.cs
NoelStephensUnity 671b83b
Refactor: minor adjustment to logging
NoelStephensUnity 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
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
111 changes: 111 additions & 0 deletions
111
com.unity.multiplayer.mlapi/Tests/Runtime/BufferDataValidationComponent.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,111 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using MLAPI.Messaging; | ||
|
|
||
| namespace MLAPI.RuntimeTests | ||
| { | ||
| /// <summary> | ||
| /// Used in conjunction with the RpcQueueTest to validate from 1 byte to (n) MaximumBufferSize | ||
| /// - Sending and Receiving a continually growing buffer up to (MaximumBufferSize) | ||
| /// - Default maximum buffer size is 1MB | ||
| /// </summary> | ||
| public class BufferDataValidationComponent : NetworkBehaviour | ||
| { | ||
| /// <summary> | ||
| /// Allows the external RPCQueueTest to begin testing or stop it | ||
| /// </summary> | ||
| public bool EnableTesting; | ||
|
|
||
| /// <summary> | ||
| /// The maximum size of the buffer to send | ||
| /// </summary> | ||
| public int MaximumBufferSize = 1 << 20; | ||
|
|
||
| /// <summary> | ||
| /// The rate at which the buffer size increases until it reaches MaximumBufferSize | ||
| /// (the default starting buffer size is 1 bytes) | ||
| /// </summary> | ||
| public int BufferSizeStart = 1; | ||
|
|
||
| /// <summary> | ||
| /// Is checked to determine if the test exited because it failed | ||
| /// </summary> | ||
| public bool TestFailed { get; internal set; } | ||
|
NoelStephensUnity marked this conversation as resolved.
|
||
|
|
||
| private bool m_WaitForValidation; | ||
| private int m_CurrentBufferSize; | ||
|
|
||
| private List<byte> m_SendBuffer; | ||
| private List<byte> m_PreCalculatedBufferValues; | ||
|
|
||
| // Start is called before the first frame update | ||
| private void Start() | ||
| { | ||
| m_WaitForValidation = false; | ||
| m_CurrentBufferSize = BufferSizeStart; | ||
| m_SendBuffer = new List<byte>(MaximumBufferSize + 1); | ||
| m_PreCalculatedBufferValues = new List<byte>(MaximumBufferSize + 1); | ||
| while (m_PreCalculatedBufferValues.Count <= MaximumBufferSize) | ||
| { | ||
| m_PreCalculatedBufferValues.Add((byte)UnityEngine.Random.Range(0, 255)); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns back whether the test has completed the total number of iterations | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public bool IsTestComplete() | ||
| { | ||
| if (m_CurrentBufferSize > MaximumBufferSize || TestFailed) | ||
| { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| // Update is called once per frame | ||
| private void Update() | ||
| { | ||
| if (NetworkManager.Singleton.IsListening && EnableTesting && !IsTestComplete() && !m_WaitForValidation) | ||
| { | ||
| m_SendBuffer.Clear(); | ||
| //Keep the current contents of the bufffer and fill the buffer with the delta difference of the buffer's current size and new size from the m_PreCalculatedBufferValues | ||
| m_SendBuffer.AddRange(m_PreCalculatedBufferValues.GetRange(0, m_CurrentBufferSize)); | ||
|
|
||
| //Make sure we don't do anything until we finish validating buffer | ||
| m_WaitForValidation = true; | ||
|
|
||
| //Send the buffer | ||
| SendBufferServerRpc(m_SendBuffer.ToArray()); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Server side RPC for testing | ||
| /// </summary> | ||
| /// <param name="parameters">server rpc parameters</param> | ||
| [ServerRpc] | ||
| private void SendBufferServerRpc(byte[] buffer) | ||
| { | ||
| TestFailed = !NetworkManagerHelper.BuffersMatch(0, buffer.Length, buffer, m_SendBuffer.ToArray()); | ||
| if (!TestFailed) | ||
| { | ||
| Debug.Log($"Tested buffer size of {m_SendBuffer.Count} -- OK"); | ||
| } | ||
|
|
||
| if (m_CurrentBufferSize == MaximumBufferSize) | ||
| { | ||
| m_CurrentBufferSize++; | ||
| } | ||
| else | ||
| { | ||
| //Increasse buffer size | ||
| m_CurrentBufferSize = m_CurrentBufferSize << 1; | ||
| } | ||
|
|
||
| m_WaitForValidation = false; | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
com.unity.multiplayer.mlapi/Tests/Runtime/BufferDataValidationComponent.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.