From 69acfc4ad97d9b3eef71e34202a806b4f8f2e039 Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Thu, 19 Aug 2021 11:58:45 -0400 Subject: [PATCH 1/4] Add a test to validate registration of metric types --- .../Runtime/Metrics/NetworkMetrics.cs | 1 - .../Tests/Editor/Metrics.meta | 3 ++ .../NetworkMetricsRegistrationTests.cs | 48 +++++++++++++++++++ .../NetworkMetricsRegistrationTests.cs.meta | 11 +++++ .../com.unity.netcode.editortests.asmdef | 29 +++++++++-- 5 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 com.unity.netcode.gameobjects/Tests/Editor/Metrics.meta create mode 100644 com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs create mode 100644 com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs.meta diff --git a/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs b/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs index ba33a0c920..d9d088757c 100644 --- a/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs +++ b/com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs @@ -4,7 +4,6 @@ using Unity.Multiplayer.NetStats.Dispatch; using Unity.Multiplayer.NetStats.Metrics; using Unity.Multiplayer.NetStatsReporting; -using UnityEngine.Profiling; namespace Unity.Netcode { diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Metrics.meta b/com.unity.netcode.gameobjects/Tests/Editor/Metrics.meta new file mode 100644 index 0000000000..bc962b1c81 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/Metrics.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 87ddfad8823c4fe192fff56b7acc241b +timeCreated: 1629386688 \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs new file mode 100644 index 0000000000..93a493d75b --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs @@ -0,0 +1,48 @@ +#if MULTIPLAYER_TOOLS + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using NUnit.Framework; +using Unity.Multiplayer.MetricTypes; +using Unity.Multiplayer.NetStats.Dispatch; +using Unity.Multiplayer.NetStats.Metrics; + +namespace Unity.Netcode.EditorTests.Metrics +{ + public class NetworkMetricsRegistrationTests + { + [Test] + public void ValidateThatAllMetricTypesAreRegistered() + { + var allMetricTypes = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(x => x.GetTypes()) + .Where(x => x.GetInterfaces().Contains(typeof(INetworkMetricEvent))) + .ToList(); + Assert.AreNotEqual(0, allMetricTypes.Count); + + var dispatcher = new NetworkMetrics().Dispatcher as MetricDispatcher; + Assert.NotNull(dispatcher); + + var collection = typeof(MetricDispatcher) + .GetField("m_Collection", BindingFlags.NonPublic | BindingFlags.Instance)? + .GetValue(dispatcher) as MetricCollection; + Assert.NotNull(collection); + + foreach (var metricType in allMetricTypes) + { + Assert.That( + collection.Metrics, + Has.Exactly(2).Matches( + eventMetric => + { + var eventType = eventMetric.GetType().GetGenericArguments()?.FirstOrDefault(); + return eventType == metricType; + })); + } + } + } +} + +#endif \ No newline at end of file diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs.meta b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs.meta new file mode 100644 index 0000000000..89ebdab722 --- /dev/null +++ b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af741f5e3d4f5544eaa68bb9bcaf54c6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef b/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef index 35dcb1ce8d..4134831e63 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef +++ b/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef @@ -3,12 +3,31 @@ "rootNamespace": "Unity.Netcode.EditorTests", "references": [ "Unity.Netcode.Runtime", - "Unity.Netcode.Editor" - ], - "optionalUnityReferences": [ - "TestAssemblies" + "Unity.Netcode.Editor", + "UnityEngine.TestRunner", + "UnityEditor.TestRunner", + "Unity.Multiplayer.MetricTypes", + "Unity.Multiplayer.NetStats" ], "includePlatforms": [ "Editor" - ] + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], + "autoReferenced": false, + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "versionDefines": [ + { + "name": "com.unity.multiplayer.tools", + "expression": "", + "define": "MULTIPLAYER_TOOLS" + } + ], + "noEngineReferences": false } \ No newline at end of file From eda6ace728f9c613a3ff69467bacd9d5eebfd0eb Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Thu, 19 Aug 2021 13:49:51 -0400 Subject: [PATCH 2/4] Code review fixes --- .../NetworkMetricsRegistrationTests.cs | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs index 93a493d75b..1f243d32e1 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/Metrics/NetworkMetricsRegistrationTests.cs @@ -1,7 +1,6 @@ #if MULTIPLAYER_TOOLS using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; using NUnit.Framework; @@ -13,15 +12,14 @@ namespace Unity.Netcode.EditorTests.Metrics { public class NetworkMetricsRegistrationTests { - [Test] - public void ValidateThatAllMetricTypesAreRegistered() + static Type[] s_MetricTypes = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(x => x.GetTypes()) + .Where(x => x.GetInterfaces().Contains(typeof(INetworkMetricEvent))) + .ToArray(); + + [TestCaseSource(nameof(s_MetricTypes))] + public void ValidateThatAllMetricTypesAreRegistered(Type metricType) { - var allMetricTypes = AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(x => x.GetTypes()) - .Where(x => x.GetInterfaces().Contains(typeof(INetworkMetricEvent))) - .ToList(); - Assert.AreNotEqual(0, allMetricTypes.Count); - var dispatcher = new NetworkMetrics().Dispatcher as MetricDispatcher; Assert.NotNull(dispatcher); @@ -30,17 +28,14 @@ public void ValidateThatAllMetricTypesAreRegistered() .GetValue(dispatcher) as MetricCollection; Assert.NotNull(collection); - foreach (var metricType in allMetricTypes) - { - Assert.That( - collection.Metrics, - Has.Exactly(2).Matches( - eventMetric => - { - var eventType = eventMetric.GetType().GetGenericArguments()?.FirstOrDefault(); - return eventType == metricType; - })); - } + Assert.That( + collection.Metrics, + Has.Exactly(2).Matches( + eventMetric => + { + var eventType = eventMetric.GetType().GetGenericArguments()?.FirstOrDefault(); + return eventType == metricType; + })); } } } From 13c143ad3721ae5ac17d84ed21059aa459463d38 Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Mon, 23 Aug 2021 09:22:18 -0400 Subject: [PATCH 3/4] Update tools package version --- testproject-tools-integration/Packages/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testproject-tools-integration/Packages/manifest.json b/testproject-tools-integration/Packages/manifest.json index 596ddb24dd..df82f39aee 100644 --- a/testproject-tools-integration/Packages/manifest.json +++ b/testproject-tools-integration/Packages/manifest.json @@ -3,7 +3,7 @@ "dependencies": { "com.unity.ide.rider": "3.0.7", "com.unity.netcode.gameobjects": "file:../../com.unity.netcode.gameobjects", - "com.unity.multiplayer.tools": "0.0.1-preview.2", + "com.unity.multiplayer.tools": "0.0.1-preview.3", "com.unity.multiplayer.transport.utp": "file:../../com.unity.multiplayer.transport.utp", "com.unity.test-framework": "1.1.26", "com.unity.modules.ai": "1.0.0", From e69de010b0977e8d8b5514685f18a882979d40fe Mon Sep 17 00:00:00 2001 From: Benoit Doyon Date: Tue, 24 Aug 2021 11:05:22 -0400 Subject: [PATCH 4/4] Code review fixes --- .../com.unity.netcode.editortests.asmdef | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef b/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef index 4134831e63..1c8e0294d9 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef +++ b/com.unity.netcode.gameobjects/Tests/Editor/com.unity.netcode.editortests.asmdef @@ -4,30 +4,20 @@ "references": [ "Unity.Netcode.Runtime", "Unity.Netcode.Editor", - "UnityEngine.TestRunner", - "UnityEditor.TestRunner", "Unity.Multiplayer.MetricTypes", "Unity.Multiplayer.NetStats" ], + "optionalUnityReferences": [ + "TestAssemblies" + ], "includePlatforms": [ "Editor" ], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": true, - "precompiledReferences": [ - "nunit.framework.dll" - ], - "autoReferenced": false, - "defineConstraints": [ - "UNITY_INCLUDE_TESTS" - ], - "versionDefines": [ + "versionDefines": [ { "name": "com.unity.multiplayer.tools", "expression": "", "define": "MULTIPLAYER_TOOLS" } - ], - "noEngineReferences": false + ] } \ No newline at end of file