Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Deadlock in NUnit test

$
0
0

Hi,

In attempting to resolve an async issue I'm having, I've discovered some strange behavior in the NUnit test runner:

[Test]
public async void async_test_1()
{
    await SomeAsyncThing();
    System.Diagnostics.Debug.WriteLine("Finished execution.");
}

[Test]
public async Task async_test_2()
{
    await SomeAsyncThing();
    System.Diagnostics.Debug.WriteLine("Finished execution.");
}

private Task SomeAsyncThing()
{
    return Task.Run(() =>
    {
        System.Diagnostics.Debug.WriteLine("Executing.");
        return true;
    });
}

Running async_test_1 works fine. Running async_test_2 blocks. It outputs "Executing" and then hangs with this stack trace:

System.Threading.WaitHandle.WaitOne_internal () in 
System.Threading.WaitHandle.WaitOne (millisecondsTimeout=-1, exitContext=false) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/WaitHandle.cs:379
System.Threading.ManualResetEventSlim.Wait (millisecondsTimeout=-1, cancellationToken=The vm is not suspended.) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/ManualResetEventSlim.cs:189
System.Threading.Tasks.Task.WaitCore (millisecondsTimeout=-1, cancellationToken=The vm is not suspended., runInline=true) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:699
System.Threading.Tasks.Task.Wait (millisecondsTimeout=-1, cancellationToken=The vm is not suspended.) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:672
System.Threading.Tasks.Task.Wait () in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:649

The only syntactic difference between the two is that test 1 is declared as void whilst test 2 is declared as returning Task.

Any thoughts?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>