Search Issue Tracker

Won't Fix

Won't Fix in 1.3.X, 2.0.X



Found in [Package]




Issue ID




Editor hangs when using Assert.ThrowsAsync in a test

Package: Test-Framework


How to reproduce:
1. Open the attached “ThrowsAsyncBug” project
2. In the main menu bar, select “Window” → “General” → “Test Runner”
3. Run the “ThrowsAsync_WhenCallingAsyncTask_LocksUnityAsync” test
4. Observe the progress bar

Expected result: The progress bar finishes loading without problems
Actual result: The progress bar never finishes, putting the entire Editor in deadlock

Reproducible with: 2.0.1-exp.1 (2021.3.6f1), 2.0.1-pre.12 (2022.1.10f1), 2.0.1-pre.18 (2022.2.0b2)
Couldn’t test with: 1.1.33 (2020.3.37f1), 2.0.1-pre.18 (2023.1.0a4) (Compilation errors)

Reproducible on: Windows 10

  1. Resolution Note:

    There are no fixes planned for this Bug

  2. Resolution Note (1.3.X):

    The reason why the editor freezes is that Assert.ThrowsAync blocks the main editor thread. In general we provide IEnumerator alternatives to such calls, which will work instead, but we do not yet have one for ThrowsAsync. Until we add that in a minor release in the future, you are able to work around the issue by adding similar code. The following snippet will use an UnityTest to check on every frame update if the async method is doen running and once it is done, it will evaluate the exception.

    public IEnumerator UnityThrowsAsync_WhenCallingAsyncTask_Solution()
    yield return AssertThrowAsync<Exception>(ThrowException);

    private IEnumerator AssertThrowAsync<T>(AsyncTestDelegate code) where T : Exception
    var task = code();
    while (!task.IsCompleted)
    yield return null;

    Assert.That<Exception>(task.Exception != null && task.Exception.InnerExceptions.Count == 1 ? task.Exception.InnerException : task.Exception, new ExceptionTypeConstraint(typeof(T)));

  3. Resolution Note (2.0.X):

    Won't do any 2.0 fixes, 2.0 is never going to be released

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.