-
Notifications
You must be signed in to change notification settings - Fork 459
feat: Report metrics when network objects are spawned or destroyed/despawned. #930
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
josiemessa
merged 15 commits into
experimental/netstats-dispatcher
from
experimental/netstats/network-object-spawn-destroy
Jun 30, 2021
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6cdc325
Add new network object spawn/destroy metrics
c940eb1
Move tests into their own directory
0a63e20
Merge branch 'experimental/netstats-dispatcher' into experimental/net…
0c6442c
Move tests to their own directory, use new framework
4a9ba88
Merge branch 'experimental/netstats-dispatcher' into experimental/net…
11fa397
Fix network spawn test
150b520
Implement test for spawn call received
e456d22
Add full tests for network object spawn/destroy sent and received
92a9004
Grab network object early so we can report network object name in met…
d96c2ff
Merge branch 'experimental/netstats-dispatcher' into experimental/net…
898201d
Merge branch 'experimental/netstats-dispatcher' into experimental/net…
c8322cb
Improve tests and fix bad merge
2f76a16
Remove unused import
00092c0
Remove unnecessary changes
9054749
Add bug comment in to tests
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
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/NetworkObjects.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
148 changes: 148 additions & 0 deletions
148
...unity.multiplayer.mlapi/Tests/Runtime/Metrics/NetworkObjects/NetworkObjectMetricsTests.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,148 @@ | ||
| using System.Collections; | ||
| using System.Linq; | ||
| using MLAPI.Metrics; | ||
| using NUnit.Framework; | ||
| using Unity.Multiplayer.NetworkProfiler; | ||
| using Unity.Multiplayer.NetworkProfiler.Models; | ||
| using UnityEngine; | ||
| using UnityEngine.TestTools; | ||
|
|
||
| namespace MLAPI.RuntimeTests.Metrics.NetworkObjects | ||
| { | ||
| public class NetworkObjectMetricsTests | ||
| { | ||
| NetworkManager m_Server; | ||
| NetworkManager m_Client; | ||
| NetworkMetrics m_ClientMetrics; | ||
| NetworkMetrics m_ServerMetrics; | ||
|
|
||
| private NetworkObject m_NewNetworkObject; | ||
| private const string m_NewNetworkObjectName = "TestNetworkObjectToSpawn"; | ||
|
|
||
| [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>(); | ||
|
|
||
| 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_ClientMetrics = m_Client.NetworkMetrics as NetworkMetrics; | ||
| m_ServerMetrics = m_Server.NetworkMetrics as NetworkMetrics; | ||
|
|
||
| var gameObject = new GameObject(m_NewNetworkObjectName); | ||
| m_NewNetworkObject = gameObject.AddComponent<NetworkObject>(); | ||
| m_NewNetworkObject.NetworkManagerOwner = m_Server; | ||
| } | ||
|
|
||
| [UnityTearDown] | ||
| public IEnumerator TearDown() | ||
| { | ||
| MultiInstanceHelpers.Destroy(); | ||
|
|
||
| yield return null; | ||
| } | ||
|
|
||
| [UnityTest] | ||
| public IEnumerator TrackNetworkObjectSpawnSentMetric() | ||
| { | ||
| var waitForMetricEvent = new WaitForMetricValues<ObjectSpawnedEvent>(m_ServerMetrics.Dispatcher, MetricNames.ObjectSpawnedSent); | ||
|
|
||
| m_NewNetworkObject.Spawn(); | ||
|
|
||
| yield return waitForMetricEvent.WaitForAFewFrames(); | ||
|
|
||
| var objectSpawnedSentMetricValues = waitForMetricEvent.EnsureMetricValuesHaveBeenFound(); | ||
| Assert.AreEqual(1, objectSpawnedSentMetricValues.Count); | ||
|
|
||
| var objectSpawned = objectSpawnedSentMetricValues.First(); | ||
| Assert.AreEqual(m_Client.LocalClientId, objectSpawned.Connection.Id); | ||
| Assert.AreEqual(m_NewNetworkObjectName, objectSpawned.NetworkId.Name); | ||
| } | ||
|
|
||
| [UnityTest] | ||
| public IEnumerator TrackNetworkObjectSpawnReceivedMetric() | ||
| { | ||
| var waitForMetricEvent = new WaitForMetricValues<ObjectSpawnedEvent>(m_ClientMetrics.Dispatcher, MetricNames.ObjectSpawnedReceived); | ||
|
|
||
| m_NewNetworkObject.Spawn(); | ||
|
|
||
| yield return waitForMetricEvent.WaitForAFewFrames(); | ||
|
|
||
| var objectSpawnedReceivedMetricValues = waitForMetricEvent.EnsureMetricValuesHaveBeenFound(); | ||
| Assert.AreEqual(1, objectSpawnedReceivedMetricValues.Count); | ||
|
|
||
| var objectSpawned = objectSpawnedReceivedMetricValues.First(); | ||
| Assert.AreEqual(m_Server.LocalClientId, objectSpawned.Connection.Id); | ||
| Assert.AreEqual(m_NewNetworkObject.NetworkObjectId, objectSpawned.NetworkId.NetworkId); | ||
| // Bug: this should not be the name of the network object | ||
| // Assert.AreEqual("Player(Clone)", objectSpawned.NetworkId.Name); // What? | ||
| } | ||
|
|
||
| [UnityTest] | ||
| public IEnumerator TrackNetworkObjectDestroySentMetric() | ||
| { | ||
| m_NewNetworkObject.Spawn(); | ||
|
|
||
| var waitForMetricEvent = new WaitForMetricValues<ObjectDestroyedEvent>(m_ServerMetrics.Dispatcher, MetricNames.ObjectDestroyedSent); | ||
| // TODO: is there a better way of waiting here? | ||
| yield return waitForMetricEvent.WaitForAFewFrames(); | ||
|
|
||
| m_Server.SpawnManager.OnDespawnObject(m_NewNetworkObject, true); | ||
|
|
||
| yield return waitForMetricEvent.WaitForAFewFrames(); | ||
|
|
||
| var objectDestroyedSentMetricValues = waitForMetricEvent.EnsureMetricValuesHaveBeenFound(); | ||
| // As there's a client and server, this event is emitted twice. | ||
| Assert.AreEqual(2, objectDestroyedSentMetricValues.Count); | ||
|
|
||
| var objectDestroyed = objectDestroyedSentMetricValues.Last(); | ||
| Assert.AreEqual(m_Client.LocalClientId, objectDestroyed.Connection.Id); | ||
| Assert.AreEqual(m_NewNetworkObjectName, objectDestroyed.NetworkId.Name); | ||
| } | ||
|
|
||
| [UnityTest] | ||
| public IEnumerator TrackNetworkObjectDestroyReceivedMetric() | ||
| { | ||
| m_NewNetworkObject.Spawn(); | ||
| var waitForMetricEvent = new WaitForMetricValues<ObjectDestroyedEvent>(m_ClientMetrics.Dispatcher, MetricNames.ObjectDestroyedReceived); | ||
|
|
||
| yield return waitForMetricEvent.WaitForAFewFrames(); | ||
|
|
||
| m_Server.SpawnManager.OnDespawnObject(m_NewNetworkObject, true); | ||
| yield return waitForMetricEvent.Wait(60); | ||
|
|
||
| var objectDestroyedReceivedMetricValues = waitForMetricEvent.EnsureMetricValuesHaveBeenFound(); | ||
| Assert.AreEqual(1, objectDestroyedReceivedMetricValues.Count); | ||
|
|
||
| var objectDestroyed = objectDestroyedReceivedMetricValues.First(); | ||
| Assert.AreEqual(m_Server.LocalClientId, objectDestroyed.Connection.Id); | ||
| Assert.AreEqual(m_NewNetworkObject.NetworkObjectId, objectDestroyed.NetworkId.NetworkId); | ||
| // Bug: Currently the object name is always "Player Clone" | ||
| // Assert.AreEqual(m_NewNetworkObjectName, objectDestroyed.NetworkId.Name); | ||
| } | ||
| } | ||
| } |
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.