-
Notifications
You must be signed in to change notification settings - Fork 456
Track ownership change events #931
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
bendoyon
merged 3 commits into
experimental/netstats-dispatcher
from
experimental/netstats/ownership-change
Jul 21, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
8 changes: 8 additions & 0 deletions
8
com.unity.multiplayer.mlapi/Tests/Runtime/Metrics/Ownership.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
com.unity.multiplayer.mlapi/Tests/Runtime/Metrics/OwnershipChangeMetricsTests.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,106 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Linq; | ||
using MLAPI.Metrics; | ||
using MLAPI.RuntimeTests.Metrics.NetworkVariables; | ||
using NUnit.Framework; | ||
using Unity.Multiplayer.MetricTypes; | ||
using UnityEngine; | ||
using UnityEngine.TestTools; | ||
|
||
namespace MLAPI.RuntimeTests.Metrics | ||
{ | ||
public class OwnershipChangeMetricsTests | ||
{ | ||
NetworkManager m_Server; | ||
NetworkMetrics m_ServerMetrics; | ||
NetworkManager m_Client; | ||
NetworkMetrics m_ClientMetrics; | ||
|
||
[UnitySetUp] | ||
public IEnumerator SetUp() | ||
{ | ||
if (!MultiInstanceHelpers.Create(1, out m_Server, out var clients)) | ||
{ | ||
Debug.LogError("Failed to create instances"); | ||
Assert.Fail("Failed to create instances"); | ||
} | ||
|
||
var playerPrefab = new GameObject("Player"); | ||
var networkObject = playerPrefab.AddComponent<NetworkObject>(); | ||
playerPrefab.AddComponent<NetworkVariableComponent>(); | ||
|
||
MultiInstanceHelpers.MakeNetworkedObjectTestPrefab(networkObject); | ||
|
||
m_Server.NetworkConfig.PlayerPrefab = playerPrefab; | ||
|
||
foreach (var client in clients) | ||
{ | ||
client.NetworkConfig.PlayerPrefab = playerPrefab; | ||
} | ||
|
||
if (!MultiInstanceHelpers.Start(true, m_Server, clients)) | ||
{ | ||
Debug.LogError("Failed to start instances"); | ||
Assert.Fail("Failed to start instances"); | ||
} | ||
|
||
yield return MultiInstanceHelpers.Run(MultiInstanceHelpers.WaitForClientsConnected(clients)); | ||
yield return MultiInstanceHelpers.Run(MultiInstanceHelpers.WaitForClientConnectedToServer(m_Server)); | ||
|
||
m_Client = clients.First(); | ||
m_ServerMetrics = m_Server.NetworkMetrics as NetworkMetrics; | ||
m_ClientMetrics = m_Client.NetworkMetrics as NetworkMetrics; | ||
} | ||
|
||
[UnityTearDown] | ||
public IEnumerator TearDown() | ||
{ | ||
MultiInstanceHelpers.Destroy(); | ||
|
||
yield return null; | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator TrackOwnershipChangeSentMetric() | ||
{ | ||
var gameObject = new GameObject(Guid.NewGuid().ToString()); | ||
var networkObject = gameObject.AddComponent<NetworkObject>(); | ||
networkObject.NetworkManagerOwner = m_Server; | ||
networkObject.Spawn(); | ||
|
||
yield return new WaitForSeconds(0.2f); | ||
|
||
var waitForMetricValues = new WaitForMetricValues<OwnershipChangeEvent>(m_ServerMetrics.Dispatcher, MetricNames.OwnershipChangeSent); | ||
|
||
networkObject.ChangeOwnership(1); | ||
|
||
yield return waitForMetricValues.WaitForMetricsReceived(); | ||
|
||
var metricValues = waitForMetricValues.AssertMetricValuesHaveBeenFound(); | ||
|
||
var ownershipChangeSent = metricValues.First(); | ||
Assert.AreEqual(m_Server.LocalClientId, ownershipChangeSent.Connection.Id); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator TrackOwnershipChangeReceivedMetric() | ||
{ | ||
var gameObject = new GameObject(Guid.NewGuid().ToString()); | ||
var networkObject = gameObject.AddComponent<NetworkObject>(); | ||
networkObject.NetworkManagerOwner = m_Server; | ||
networkObject.Spawn(); | ||
|
||
yield return new WaitForSeconds(0.2f); | ||
|
||
var waitForMetricValues = new WaitForMetricValues<OwnershipChangeEvent>(m_ClientMetrics.Dispatcher, MetricNames.OwnershipChangeReceived); | ||
|
||
networkObject.ChangeOwnership(1); | ||
|
||
yield return waitForMetricValues.WaitForMetricsReceived(); | ||
|
||
var metricValues = waitForMetricValues.AssertMetricValuesHaveBeenFound(); | ||
Assert.AreEqual(1, metricValues.Count); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.multiplayer.mlapi/Tests/Runtime/Metrics/OwnershipChangeMetricsTests.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.