Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Async Tests That Depend on Addressables Hang, Domain Reload Fixes

Discussion in 'Testing & Automation' started by tday_magicfuel, Feb 2, 2024.

  1. tday_magicfuel


    Apr 10, 2018
    There has been some weird behavior with async tests using test framework 1.4.2 in Unity 2022.3.18f1. The workaround I've found is also odd but maybe it can help Unity figure out what's going wrong.

    The setup:

    We have some code that loads some rules data via addressables. This data is used by many unit tests. The unit tests generally have something like `await RulesDataLoad()`. RulesDataLoad queues up some addressables loads and waits for them to finish.

    The issue:

    These tests run fine and all pass generally EXCEPT when running the tests after exiting play mode. In this instance the tests would hang at the first thing that awaits the RulesDataLoad and the test runner progress bar would be stuck (albeit cancelable). After scouring the project to make sure lingering data isn't left over in some manner we still experienced the same issue. In fact the tests would hang after running a totally blank scene that doesn't even do anything.

    The issue happens with play & edit mode tests both.

    After any code recompile the tests would go back to normal presumably because of domain reload or some other mechanism in Unity clearing up whatever was causing the issue/conflict. We didn't want to force code to recompile every time exiting play mode so instead I made an editor script that adds a menu item that will force a domain reload before running the tests:

    The workaround:

    Code (CSharp):
    2.         [MenuItem("MFG/Run Edit Mode Tests")]
    3.         public static void RunEditModeTests()
    4.         {
    5.             MFGTestRun.RunTests(TestMode.EditMode);
    6.         }
    8.         private static void RunTests(TestMode testModeToRun)
    9.         {
    10.             EditorUtility.RequestScriptReload();
    11.             TestRunnerApi testRunnerApi = ScriptableObject.CreateInstance<TestRunnerApi>();
    12.             Filter filter = new()
    13.             {
    14.                 testMode = testModeToRun
    15.             };
    17.             testRunnerApi.Execute(new ExecutionSettings(filter));
    18.         }
    So long as I run the tests from this button now the tests work as expected. But this really seems like a bug with how the test framework & addressables interact. Other async tests that don't depend on addressables seem to not hang. Happy to provide more context and data if it could help narrow down what's gone wrong.
    Last edited: Feb 2, 2024
    sandolkakos and rtande_MFG like this.