Add a unit test to verify that an unawaited task reports exceptions

master
Artem Perepelitsa 2021-10-16 12:18:52 +03:00
parent b6b0b4000d
commit c31b78e45e
1 changed files with 22 additions and 0 deletions

View File

@ -366,6 +366,28 @@ namespace Cysharp.Threading.TasksTests
UniTaskScheduler.UnobservedTaskException -= action; UniTaskScheduler.UnobservedTaskException -= action;
}); });
[UnityTest]
public IEnumerator ThrowExceptionUnawaited() => UniTask.ToCoroutine(async () =>
{
LogAssert.Expect(LogType.Exception, "Exception: MyException");
#pragma warning disable 1998
async UniTask Throw() => throw new Exception("MyException");
#pragma warning restore 1998
#pragma warning disable 4014
Throw();
#pragma warning restore 4014
await UniTask.DelayFrame(3);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
await UniTask.DelayFrame(1);
});
async UniTask InException1() async UniTask InException1()
{ {
await UniTask.Yield(); await UniTask.Yield();