-
Couldn't load subscription status.
- Fork 80
[USDU-407] Add automated tests for Analytics #398
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
base: dev
Are you sure you want to change the base?
Changes from all commits
4cf765c
bbe7752
f5baed0
756fbb4
c327942
b92a095
678ac6f
27e2dbc
021fec9
079bc20
d5018a8
f8b2a18
00f3942
aa6bc05
370d07c
38c98f6
e98e0f9
d7ad1f1
4fa0878
2e7398e
2fba851
5908426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| invalidFile |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| # if UNITY_2023_3_OR_NEWER | ||
|
|
||
| using System.Collections; | ||
| using NUnit.Framework; | ||
| using UnityEditor; | ||
| using UnityEngine; | ||
| using UnityEngine.TestTools; | ||
|
|
||
| namespace Unity.Formats.USD.Tests | ||
| { | ||
| public class EditorAnalyticsBaseFixture : BaseFixtureEditor | ||
| { | ||
| protected const string k_TestPrefabName = "TestPrefab"; | ||
| protected static string[] usdExtensions = new string[] { TestUtility.FileExtension.Usd, TestUtility.FileExtension.Usda, TestUtility.FileExtension.Usdc }; | ||
|
|
||
| protected struct UsdAnalyticsTypes | ||
| { | ||
| public const string Import = "editor.USDFileImport"; | ||
| public const string ReImport = "editor.USDFileReimport"; | ||
| public const string Export = "editor.USDFileExport"; | ||
| } | ||
|
|
||
| public enum ImportMethods | ||
| { | ||
| AsGameObject, | ||
| AsPrefab, | ||
| AsTimelineRecording | ||
| } | ||
|
|
||
| bool m_initialAnalyticsSetting; | ||
| bool m_initialRecordEventsSetting; | ||
| bool m_initialSendEventsImmediatelySetting; | ||
|
|
||
| [OneTimeSetUp] | ||
| public void SetEditorAnalyticsSettings() | ||
| { | ||
| m_initialAnalyticsSetting = EditorAnalytics.enabled; | ||
| m_initialRecordEventsSetting = EditorAnalytics.recordEventsEnabled; | ||
| m_initialSendEventsImmediatelySetting = EditorAnalytics.SendAnalyticsEventsImmediately; | ||
|
|
||
| EditorAnalytics.enabled = true; | ||
| EditorAnalytics.recordEventsEnabled = true; | ||
| EditorAnalytics.SendAnalyticsEventsImmediately = true; | ||
| } | ||
|
|
||
| [OneTimeTearDown] | ||
| public void RevertEditorAnalyticsSettings() | ||
| { | ||
| // Maybe implmeent a package clean up here | ||
|
|
||
| EditorAnalytics.enabled = m_initialAnalyticsSetting; | ||
| EditorAnalytics.recordEventsEnabled = m_initialRecordEventsSetting; | ||
| EditorAnalytics.SendAnalyticsEventsImmediately = m_initialSendEventsImmediatelySetting; | ||
| } | ||
|
|
||
| [SetUp] | ||
| public void ResetEventList() | ||
| { | ||
| DebuggerEventListHandler.ClearEventList(); | ||
| InitUsd.Initialize(); | ||
| } | ||
|
|
||
| public IEnumerator WaitForUsdAnalytics<T>(string expectedType, System.Action<T> actualEvent, float attemptTimeLimitMs = 1500) where T: UsdAnalyticsEvent | ||
| { | ||
| bool found = false; | ||
| var stopWatch = System.Diagnostics.Stopwatch.StartNew(); | ||
|
|
||
| while (!found && stopWatch.Elapsed.TotalMilliseconds < attemptTimeLimitMs) | ||
| { | ||
| T expectedAnalyticsEvent = null; | ||
| foreach (var concattedEvent in DebuggerEventListHandler.fetchEventList()) | ||
| { | ||
| if (!concattedEvent.Contains(expectedType)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var splitEvents = concattedEvent.Split("\n"); | ||
| var usdIndex = FindUsdAnalyticsIndex(expectedType, splitEvents); | ||
| var usdEvent = JsonUtility.FromJson<T>(splitEvents[usdIndex]); | ||
|
|
||
| if (usdEvent.type.Contains(expectedType)) | ||
| { | ||
| expectedAnalyticsEvent = usdEvent; | ||
|
|
||
| actualEvent(expectedAnalyticsEvent); | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| DebuggerEventListHandler.ClearEventList(); | ||
|
|
||
| yield return null; | ||
| } | ||
| } | ||
|
|
||
| private int FindUsdAnalyticsIndex(string expectedType, string[] splitEvents) | ||
| { | ||
| for (int index = 0; index < splitEvents.Length; index++) | ||
| { | ||
| if (splitEvents[index].Contains(expectedType)) | ||
| { | ||
| return index; | ||
| } | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
| } | ||
|
|
||
| public class UsdAnalyticsEvent | ||
| { | ||
| public string type; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I understanding correctly that this actually stores the event name string eg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nono its the former, its the event name, i'll change it to something like "name" or "eventName" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually i cant change this as the result json's variable is called "type" and as far as i know Unity's JsonUtility does not have something similar to |
||
| } | ||
|
|
||
| public class UsdAnalyticsEventImport: UsdAnalyticsEvent | ||
| { | ||
| public UsdEditorAnalytics.ImportAnalyticsData msg; | ||
| } | ||
|
|
||
| public class UsdAnalyticsEventReImport : UsdAnalyticsEvent | ||
| { | ||
| public UsdEditorAnalytics.ReimportAnalyticsData msg; | ||
| } | ||
|
|
||
| public class UsdAnalyticsEventExport : UsdAnalyticsEvent | ||
| { | ||
| public UsdEditorAnalytics.ExportAnalyticsData msg; | ||
| } | ||
| } | ||
| #endif | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we feed back further detail on the failure by also logging the exception?