|
1 | 1 | using System.Collections;
|
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Linq;
|
3 | 4 | using MLAPI.Metrics;
|
4 | 5 | using NUnit.Framework;
|
@@ -144,5 +145,80 @@ public IEnumerator TrackNetworkObjectDestroyReceivedMetric()
|
144 | 145 | // Bug: Currently the object name is always "Player Clone"
|
145 | 146 | // Assert.AreEqual(m_NewNetworkObjectName, objectDestroyed.NetworkId.Name);
|
146 | 147 | }
|
| 148 | + |
| 149 | + [UnityTest] |
| 150 | + public IEnumerator TrackMultipleNetworkObjectDestroySentMetric() |
| 151 | + { |
| 152 | + m_NewNetworkObject.Spawn(); |
| 153 | + |
| 154 | + // Spawn another network object so we can hide multiple. |
| 155 | + var gameObject = new GameObject(m_NewNetworkObjectName); |
| 156 | + var anotherNetworkObject = gameObject.AddComponent<NetworkObject>(); |
| 157 | + anotherNetworkObject.NetworkManagerOwner = m_Server; |
| 158 | + anotherNetworkObject.Spawn(); |
| 159 | + |
| 160 | + var waitForMetricEvent = new WaitForMetricValues<ObjectDestroyedEvent>(m_ServerMetrics.Dispatcher, MetricNames.ObjectDestroyedSent); |
| 161 | + yield return waitForMetricEvent.WaitForAFewFrames(); |
| 162 | + |
| 163 | + NetworkObject.NetworkHide(new List<NetworkObject>{m_NewNetworkObject, anotherNetworkObject}, m_Client.LocalClientId); |
| 164 | + |
| 165 | + yield return waitForMetricEvent.Wait(60); |
| 166 | + |
| 167 | + var objectDestroyedSentMetricValues = waitForMetricEvent.EnsureMetricValuesHaveBeenFound(); |
| 168 | + // As there's a client and server, this event is emitted twice. |
| 169 | + Assert.AreEqual(2, objectDestroyedSentMetricValues.Count); |
| 170 | + |
| 171 | + var networkIDFound = true; |
| 172 | + var networkNameFound = true; |
| 173 | + // not sure that we can guarantee the order of these so just ensure the data is in the received metrics. |
| 174 | + foreach (var metricValue in objectDestroyedSentMetricValues) |
| 175 | + { |
| 176 | + Assert.AreEqual(m_Client.LocalClientId, metricValue.Connection.Id); |
| 177 | + networkIDFound &= metricValue.NetworkId.NetworkId == m_NewNetworkObject.NetworkObjectId || metricValue.NetworkId.NetworkId == anotherNetworkObject.NetworkObjectId; |
| 178 | + networkNameFound &= metricValue.NetworkId.Name == m_NewNetworkObject.name || metricValue.NetworkId.Name == anotherNetworkObject.name; |
| 179 | + } |
| 180 | + Assert.IsTrue(networkIDFound); |
| 181 | + Assert.IsTrue(networkNameFound); |
| 182 | + } |
| 183 | + |
| 184 | + [UnityTest] |
| 185 | + public IEnumerator TrackMultipleNetworkObjectSpawnSentMetric() |
| 186 | + { |
| 187 | + m_NewNetworkObject.Spawn(); |
| 188 | + |
| 189 | + // Spawn another network object so we can hide multiple. |
| 190 | + var gameObject = new GameObject(m_NewNetworkObjectName); |
| 191 | + var anotherNetworkObject = gameObject.AddComponent<NetworkObject>(); |
| 192 | + anotherNetworkObject.NetworkManagerOwner = m_Server; |
| 193 | + anotherNetworkObject.Spawn(); |
| 194 | + |
| 195 | + var waitForMetricEvent = new WaitForMetricValues<ObjectSpawnedEvent>(m_ServerMetrics.Dispatcher, MetricNames.ObjectSpawnedSent); |
| 196 | + yield return waitForMetricEvent.WaitForAFewFrames(); |
| 197 | + |
| 198 | + NetworkObject.NetworkHide(new List<NetworkObject>{m_NewNetworkObject, anotherNetworkObject}, m_Client.LocalClientId); |
| 199 | + |
| 200 | + yield return waitForMetricEvent.WaitForAFewFrames(); |
| 201 | + |
| 202 | + NetworkObject.NetworkShow(new List<NetworkObject>{m_NewNetworkObject, anotherNetworkObject}, m_Client.LocalClientId); |
| 203 | + |
| 204 | + yield return waitForMetricEvent.Wait(60); |
| 205 | + |
| 206 | + var objectSpawnedSentMetricValues = waitForMetricEvent.EnsureMetricValuesHaveBeenFound(); |
| 207 | + // As there's a client and server, this event is emitted twice. |
| 208 | + Assert.AreEqual(2, objectSpawnedSentMetricValues.Count); |
| 209 | + |
| 210 | + var networkIDFound = true; |
| 211 | + var networkNameFound = true; |
| 212 | + // not sure that we can guarantee the order of these so just ensure the data is in the received metrics. |
| 213 | + foreach (var metricValue in objectSpawnedSentMetricValues) |
| 214 | + { |
| 215 | + Assert.AreEqual(m_Client.LocalClientId, metricValue.Connection.Id); |
| 216 | + networkIDFound &= metricValue.NetworkId.NetworkId == m_NewNetworkObject.NetworkObjectId || metricValue.NetworkId.NetworkId == anotherNetworkObject.NetworkObjectId; |
| 217 | + networkNameFound &= metricValue.NetworkId.Name == m_NewNetworkObject.name || metricValue.NetworkId.Name == anotherNetworkObject.name; |
| 218 | + } |
| 219 | + |
| 220 | + Assert.IsTrue(networkIDFound); |
| 221 | + Assert.IsTrue(networkNameFound); |
| 222 | + } |
147 | 223 | }
|
148 | 224 | }
|
0 commit comments