Skip to content

Commit fd44d53

Browse files
authored
feat: Add a test to validate registration of metric types (#1072)
1 parent 93c8db0 commit fd44d53

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Unity.Multiplayer.NetStats.Dispatch;
55
using Unity.Multiplayer.NetStats.Metrics;
66
using Unity.Multiplayer.NetStatsReporting;
7-
using UnityEngine.Profiling;
87

98
namespace Unity.Netcode
109
{

com.unity.netcode.gameobjects/Tests/Editor/Metrics.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#if MULTIPLAYER_TOOLS
2+
3+
using System;
4+
using System.Linq;
5+
using System.Reflection;
6+
using NUnit.Framework;
7+
using Unity.Multiplayer.MetricTypes;
8+
using Unity.Multiplayer.NetStats.Dispatch;
9+
using Unity.Multiplayer.NetStats.Metrics;
10+
11+
namespace Unity.Netcode.EditorTests.Metrics
12+
{
13+
public class NetworkMetricsRegistrationTests
14+
{
15+
static Type[] s_MetricTypes = AppDomain.CurrentDomain.GetAssemblies()
16+
.SelectMany(x => x.GetTypes())
17+
.Where(x => x.GetInterfaces().Contains(typeof(INetworkMetricEvent)))
18+
.ToArray();
19+
20+
[TestCaseSource(nameof(s_MetricTypes))]
21+
public void ValidateThatAllMetricTypesAreRegistered(Type metricType)
22+
{
23+
var dispatcher = new NetworkMetrics().Dispatcher as MetricDispatcher;
24+
Assert.NotNull(dispatcher);
25+
26+
var collection = typeof(MetricDispatcher)
27+
.GetField("m_Collection", BindingFlags.NonPublic | BindingFlags.Instance)?
28+
.GetValue(dispatcher) as MetricCollection;
29+
Assert.NotNull(collection);
30+
31+
Assert.That(
32+
collection.Metrics,
33+
Has.Exactly(2).Matches<IEventMetric>(
34+
eventMetric =>
35+
{
36+
var eventType = eventMetric.GetType().GetGenericArguments()?.FirstOrDefault();
37+
return eventType == metricType;
38+
}));
39+
}
40+
}
41+
}
42+
43+
#endif

com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
"rootNamespace": "Unity.Netcode.EditorTests",
44
"references": [
55
"Unity.Netcode.Runtime",
6-
"Unity.Netcode.Editor"
6+
"Unity.Netcode.Editor",
7+
"Unity.Multiplayer.MetricTypes",
8+
"Unity.Multiplayer.NetStats"
79
],
810
"optionalUnityReferences": [
911
"TestAssemblies"
1012
],
1113
"includePlatforms": [
1214
"Editor"
15+
],
16+
"versionDefines": [
17+
{
18+
"name": "com.unity.multiplayer.tools",
19+
"expression": "",
20+
"define": "MULTIPLAYER_TOOLS"
21+
}
1322
]
1423
}

testproject-tools-integration/Packages/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"dependencies": {
44
"com.unity.ide.rider": "3.0.7",
55
"com.unity.netcode.gameobjects": "file:../../com.unity.netcode.gameobjects",
6-
"com.unity.multiplayer.tools": "0.0.1-preview.2",
6+
"com.unity.multiplayer.tools": "0.0.1-preview.3",
77
"com.unity.multiplayer.transport.utp": "file:../../com.unity.multiplayer.transport.utp",
88
"com.unity.test-framework": "1.1.26",
99
"com.unity.modules.ai": "1.0.0",

0 commit comments

Comments
 (0)