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

Async iterator tests hang xunit on CoreCLR #29735

Closed
jcouv opened this issue Sep 8, 2018 · 2 comments
Closed

Async iterator tests hang xunit on CoreCLR #29735

jcouv opened this issue Sep 8, 2018 · 2 comments

Comments

@jcouv
Copy link
Member

jcouv commented Sep 8, 2018

I've temporarily marked the affected async-iterator tests as conditional (windows/desktop-only).

Below is one example, which involves exceptions being thrown. The strange thing is that adding a simple Console.Write("CAUGHT") call makes the problem go away.

Other than that, many (if not all) async iterators also hang on CoreCLR, despite not involving exceptions.

        [Fact]
        public void TestThrownException_WhilePromiseActive()
        {
            string source = @"
using static System.Console;
class C
{
    public static async System.Threading.Tasks.Task Main()
    {
        var enumerator = new C().M().GetAsyncEnumerator();
        await enumerator.WaitForNextAsync();

        var value = enumerator.TryGetNext(out bool success);
        Assert(success);
        Assert(value == 42);

        enumerator.TryGetNext(out success);
        Assert(!success);

        try
        {
            await enumerator.WaitForNextAsync();
            Write(""UNREACHABLE"");
        }
        catch (System.Exception e)
        {
            Assert(e.Message == ""message"");
            //Write($""CAUGHT""); // crash only happens if this line is commented out
        }
        Write(""Done"");
    }
    async System.Collections.Generic.IAsyncEnumerable<int> M()
    {
        yield return 42;
        await new System.Threading.Tasks.ValueTask(System.Threading.Tasks.Task.Delay(100));
        bool b = true;
        if (b) throw new System.Exception(""message"");
        Write(""UNREACHABLE2"");
    }
    static void Assert(bool b)
    {
        if (!b) throw null;
    }
}";
            var comp = CreateCompilationWithTasksExtensions(new[] { source, s_common }, options: TestOptions.DebugExe);
            comp.VerifyDiagnostics();
            CompileAndVerify(comp, expectedOutput: "Done");
        }

To run this test on CoreCLR:

"C:\Program Files\dotnet\dotnet.exe" exec --depsfile c:\repos\roslyn\Binaries\Debug\UnitTests\Microsoft.CodeAnalysis.CSharp.Emit.UnitTests\netcoreapp2.0\Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.deps.json --runtimeconfig c:\repos\roslyn\Binaries\Debug\UnitTests\Microsoft.CodeAnalysis.CSharp.Emit.UnitTests\netcoreapp2.0\Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.runtimeconfig.json C:\Users\dumky\.nuget\packages\xunit.runner.console\2.3.1\tools\netcoreapp2.0\xunit.console.dll c:\repos\roslyn\Binaries\Debug\UnitTests\Microsoft.CodeAnalysis.CSharp.Emit.UnitTests\netcoreapp2.0\Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.dll -xml c:\repos\roslyn\Binaries\Debug\UnitTests\xUnitResults\Microsoft.CodeAnalysis.CSharp.Emit.UnitTests.xml -parallel none -method Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen.CodeGenAsyncIteratorTests.TestThrownException_WhilePromiseActive

Relates to PR #28218

@jcouv jcouv self-assigned this Sep 8, 2018
@jcouv jcouv changed the title Async iterator test with Exception hangs xunit on CoreCLR Async iterator tests hang xunit on CoreCLR Sep 8, 2018
@jaredpar jaredpar added the Bug label Sep 10, 2018
@jcouv
Copy link
Member Author

jcouv commented Sep 11, 2018

From discussion with Jeff Schwartz, this is a known issue with resolution rules and the TPA (trusted platform assemblies). Even though our test framework is ready to provide System.Threading.Tasks.Extensions version 4.2, it fails to load because the version in the TPA is 4.1 (the lookup gets downgraded and the result is then judged inacceptable).

Update (9/11/2018):
It turns out the issue is not with loading System.Threading.Tasks.Extensions after all. The Roslyn test utilities first ask the default AssemblyLoadContext for that assembly (which internally throws a FileNotFoundException, but eventually returns null) but then loads our own provided image via LoadAsStream). Jeff will take another look.

@jcouv
Copy link
Member Author

jcouv commented Oct 8, 2018

This was resolved by making sure that the AsyncVoidMethodBuilder is marked as complete when we dispose the state machine.
PR #30104

@jcouv jcouv closed this as completed Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants