-
Notifications
You must be signed in to change notification settings - Fork 450
test: connection approval and invalid NetworkPrefabs within NetworkConfig.NetworkPrefabs #825
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Text; | ||
using System.Collections; | ||
using UnityEngine; | ||
using UnityEngine.TestTools; | ||
using NUnit.Framework; | ||
|
||
namespace MLAPI.RuntimeTests | ||
{ | ||
|
||
public class ConnectionApprovalTests | ||
{ | ||
|
||
private Guid m_ValidationToken; | ||
|
||
private bool m_IsValidated; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
// Create, instantiate, and host | ||
Assert.IsTrue(NetworkManagerHelper.StartNetworkManager(out _,NetworkManagerHelper.NetworkManagerOperatingMode.None)); | ||
m_ValidationToken = Guid.NewGuid(); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator ConnectionApproval() | ||
{ | ||
NetworkManagerHelper.NetworkManagerObject.ConnectionApprovalCallback += NetworkManagerObject_ConnectionApprovalCallback; | ||
NetworkManagerHelper.NetworkManagerObject.NetworkConfig.ConnectionApproval = true; | ||
NetworkManagerHelper.NetworkManagerObject.NetworkConfig.PlayerPrefab = null; | ||
NetworkManagerHelper.NetworkManagerObject.NetworkConfig.ConnectionData = Encoding.UTF8.GetBytes(m_ValidationToken.ToString()); | ||
m_IsValidated = false; | ||
NetworkManagerHelper.NetworkManagerObject.StartHost(); | ||
|
||
var timeOut = Time.realtimeSinceStartup + 3.0f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume these 3.0 & 0.01 time values have a rationale to them and are compatible with how things operate on Yamato? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep... it was a "wild guess" of what to realistically expect Yamato's read/write times when under a heavy load (worst case scenario)...so far it seems to be working out ok... :) |
||
var timedOut = false; | ||
while(!m_IsValidated) | ||
{ | ||
yield return new WaitForSeconds(0.01f); | ||
if(timeOut < Time.realtimeSinceStartup) | ||
{ | ||
timedOut = true; | ||
} | ||
} | ||
|
||
//Make sure we didn't time out | ||
Assert.False(timedOut); | ||
Assert.True(m_IsValidated); | ||
} | ||
|
||
private void NetworkManagerObject_ConnectionApprovalCallback(byte[] connectionData, ulong clientId, NetworkManager.ConnectionApprovedDelegate callback) | ||
{ | ||
var stringGuid = Encoding.UTF8.GetString(connectionData); | ||
if(m_ValidationToken.ToString() == stringGuid) | ||
{ | ||
m_IsValidated = true; | ||
} | ||
callback(false, null, m_IsValidated, null, null); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
// Stop, shutdown, and destroy | ||
NetworkManagerHelper.ShutdownNetworkManager(); | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NoelStephensUnity @TwoTenPvP I like these helpers to simplify unit tests, but I think we may now have 2 sets of helpers. Is this right? Can we merge them into one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good idea.