Skip to content
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

[USDU-407] Add automated tests for Analytics #398

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from

Conversation

lee-aandrew
Copy link
Contributor

Purpose of this PR

Analytics have been added for our USD package giving us various information about the usage of the package
We thought it would have be needed to have some automated test cases for the analytics

Ticket/Jira #:
[USDU-407]

Testing

Functional Testing status:
Adds functional testcases for the analytics for the following parts:

  • Import
  • Export
  • Re-import (refresh / update)

Could not add planned Recorder analytics automated testing as a lot of recorder aspect is private / internal, and unless I use reflections I cannot instantiate a lot of the classes that I would need to set up the test
LMK if you guys think its needed

Performance Testing status:

Overall Product Risks

Complexity:

Halo Effect:

Additional information

Note to reviewers:

Reminder:

  • Add entry in CHANGELOG.md (if applicable)

@lee-aandrew lee-aandrew requested review from vickycl and a team July 10, 2023 01:55
@SimonBoorer
Copy link
Collaborator

Are you aware the tests are failing on 2023.1 and newer?

Library\PackageCache\com.unity.formats.usd.tests@090deec1ff8c\Tests\Editor\EditorAnalyticsBaseFixture.cs(8,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

Copy link
Collaborator

@michaeljblain michaeljblain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions. Looks like tests are still failing on trunk.

package/com.unity.formats.usd/Tests/Common/BaseFixture.cs Outdated Show resolved Hide resolved
}
catch
{
Debug.Log("Artifact Clean up has failed - This should not happen in most cases, but even if so, the test case should not be affected.");
Copy link
Collaborator

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?

@lee-aandrew
Copy link
Contributor Author

lee-aandrew commented Jul 25, 2023

Stuck due to problem on the analytics side - Mike Stowell is looking into the issue

Requires Mike's fixes: Link

…om the manifest.json | Adds analytics to the formats.usd package
…ies/usd-unity-sdk into AddAnalyticsTest

# Conflicts:
#	package/com.unity.formats.usd/Tests/Common/BaseFixture.cs
#	package/com.unity.formats.usd/Tests/Common/Data/Material/Invalid.format
#	package/com.unity.formats.usd/Tests/Common/Data/Material/Invalid.format.meta
#	package/com.unity.formats.usd/Tests/Common/Data/Material/InvalidContent.usda
#	package/com.unity.formats.usd/Tests/Common/Data/Material/InvalidContent.usda.meta
#	package/com.unity.formats.usd/Tests/Common/Data/Material/Kiki_Blendshape.usd
#	package/com.unity.formats.usd/Tests/Common/Data/Material/Kiki_Blendshape.usd.meta
#	package/com.unity.formats.usd/Tests/Editor/EditorAnalyticsBaseFixture.cs
#	package/com.unity.formats.usd/Tests/Editor/EditorExportAnalyticsTests.cs
#	package/com.unity.formats.usd/Tests/Editor/EditorExportAnalyticsTests.cs.meta
#	package/com.unity.formats.usd/Tests/Editor/EditorImportAnalyticsTests.cs
#	package/com.unity.formats.usd/Tests/Editor/EditorImportAnalyticsTests.cs.meta
#	package/com.unity.formats.usd/Tests/Editor/EditorReImportAnalyticsTests.cs
#	package/com.unity.formats.usd/Tests/Editor/EditorReImportAnalyticsTests.cs.meta
#	package/com.unity.formats.usd/Tests/Editor/Unity.Formats.USD.Tests.Editor.asmdef
@lee-aandrew lee-aandrew changed the base branch from dev to add-test-export-data-structure-kept July 26, 2023 20:46
@lee-aandrew lee-aandrew changed the base branch from add-test-export-data-structure-kept to dev July 26, 2023 20:46
@@ -13,7 +13,11 @@ test_{{ platform.name }}_{{ editor.version }}:
UPMCI_PKG: "upm-ci-utils@stable"
commands:
- npm install {% if platform.name == "win" %}"%UPMCI_PKG%"{% else %}"$UPMCI_PKG"{% endif %} -g --registry {{ registry.npm }}
- upm-ci package test -u {{ editor.version }} --package-path package/com.unity.formats.usd --type package-tests --extra-utr-arg="--api-profile=NET_4_6"
{% if editor.version == "trunk" %}
- upm-ci package test -u {{ editor.version }} --package-path package/com.unity.formats.usd --type package-tests --extra-utr-arg="--api-profile=NET_4_6" --extra-editor-arg=-editorAnalyticsTestMode
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is behind an if statement as there was a bug in the analytics side where if this was set for versions less than trunk, it would crash the editor

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should specify 'trunk' here as it isn't robust for the future. Eventually trunk will be newer that 2023 and the '23 LTS won't be tested/ the tests will run without this editor arg being set. I'm not sure what the correct answer is though :)

Copy link
Collaborator

@vickycl vickycl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small fixes and clean up suggested, but otherwise good so far!

@@ -1,11 +1,12 @@
{
"dependencies": {
"com.unity.analytics": "3.5.3",
"com.unity.editor-analytics-debugger": "0.1.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ok in 2019.4?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this is leftover from when I initially started the review 😂

@@ -13,7 +13,11 @@ test_{{ platform.name }}_{{ editor.version }}:
UPMCI_PKG: "upm-ci-utils@stable"
commands:
- npm install {% if platform.name == "win" %}"%UPMCI_PKG%"{% else %}"$UPMCI_PKG"{% endif %} -g --registry {{ registry.npm }}
- upm-ci package test -u {{ editor.version }} --package-path package/com.unity.formats.usd --type package-tests --extra-utr-arg="--api-profile=NET_4_6"
{% if editor.version == "trunk" %}
- upm-ci package test -u {{ editor.version }} --package-path package/com.unity.formats.usd --type package-tests --extra-utr-arg="--api-profile=NET_4_6" --extra-editor-arg=-editorAnalyticsTestMode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should specify 'trunk' here as it isn't robust for the future. Eventually trunk will be newer that 2023 and the '23 LTS won't be tested/ the tests will run without this editor arg being set. I'm not sure what the correct answer is though :)

@@ -13,7 +13,11 @@ test_{{ platform.name }}_{{ editor.version }}:
UPMCI_PKG: "upm-ci-utils@stable"
commands:
- npm install {% if platform.name == "win" %}"%UPMCI_PKG%"{% else %}"$UPMCI_PKG"{% endif %} -g --registry {{ registry.npm }}
- upm-ci package test -u {{ editor.version }} --package-path package/com.unity.formats.usd --type package-tests --extra-utr-arg="--api-profile=NET_4_6"
{% if editor.version == "trunk" %}
- upm-ci package test -u {{ editor.version }} --package-path package/com.unity.formats.usd --type package-tests --extra-utr-arg="--api-profile=NET_4_6" --extra-editor-arg=-editorAnalyticsTestMode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the --extra-editor-arg=-editorAnalyticsTestMode alleviate the need for UNITY_THISISABUILDMACHINE? ie does it set the runmode to test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized i set the "UNITY_THISISABUILDMACHINE" but it never got passed over to the yamato call, and i believe our test machines already have the "UNITY_THISISABUILDMACHINE" set to true

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see what is included here, but it's quite a big asset to include for the sake of a test, and I'm also not sure whether it can be shared publicly in this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good point, i just needed an invalid USD file for a failure, in this case blendshapes, i'll look for another asset

InitUsd.Initialize();
}

public IEnumerator WaitForUsdAnalytics<T>(string expectedType, System.Action<AnalyticsEvent> expectedEvent, float attemptFrameCountLimit = 300) where T: UsdAnalyticsEvent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This frame count limit is very high- are you sure it needs to be this high?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to use c#'s stopwatch for shorter + more accurate measurement

public UsdAnalyticsEvent usd;
}

public class SharedAnalyticsEvent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared event is no longer used anywhere- can it be removed now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case can we remove a layer of abstraction and use the UsdAnalyticsEvent directly instead of the AnalyticsEvent wrapper? To simplify lines like var exportUsdEventMsg = ((UsdAnalyticsEventExport)exportEvent.usd).msg; a bit, as they're hard to parse

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for eg var exportUsdEventMsg = ((UsdAnalyticsEventExport)exportEvent).eventData; in that case would be easier to reason at a glance what it's getting

Assert.IsNotNull(exportEvent);
var exportUsdEventMsg = ((UsdAnalyticsEventExport)exportEvent.usd).msg;

Assert.IsTrue(exportUsdEventMsg.Succeeded, "Expected True for re-import Successful");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this should be 'export successful'

Assert.IsNotNull(exportEvent);
var exportUsdEventMsg = ((UsdAnalyticsEventExport)exportEvent.usd).msg;

Assert.IsTrue(exportUsdEventMsg.Succeeded, "Expected True for re-import Successful");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above :)

Assert.IsNotNull(exportEvent);
var exportUsdEventMsg = ((UsdAnalyticsEventExport)exportEvent.usd).msg;

Assert.IsFalse(exportUsdEventMsg.Succeeded, "Expected Fail for re-import Successful");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above :)


public class UsdAnalyticsEvent
{
public string type;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 editor.USDFileImport, or is it actually the C# type name of the event? If it is the former I'd suggest a more explicit variable name :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 JsonProperty


public class SharedAnalyticsEvent
{
// check if the class for this is in Unity source (if its a bit convoluted just make it)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this comment mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be removed, but i meant to check if theres a class with the same structure as "SharedAnalyticsEvent" already defined within Unity, and if so, use that instead of creating it here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants