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

MSTest/NET48 hangs with custom file converter #751

Closed
TymurGubayev opened this issue Jan 2, 2023 · 8 comments
Closed

MSTest/NET48 hangs with custom file converter #751

TymurGubayev opened this issue Jan 2, 2023 · 8 comments

Comments

@TymurGubayev
Copy link

Description

Using MSTest 3.0.2, Verify commit cc00a56 (02.01.2023) and custom file converter from Verify.WinForms, the very basic test (Verify(new Button())) hangs.

Minimal Repro

Copy VerifyWinForms.cs
to Verify.MSTest.Tests/WinForms/VerifyWinForms.cs.

Create Verify.MSTest.Tests/WinForms/UnitTest1.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UnitTestProject1;

[TestClass]
public class UnitTest1 : VerifyBase
{

    [ClassInitialize]
    public static void Init(TestContext context)
        => VerifyWinForms.Enable();

    [TestMethod]
    public Task TestMethod2()
    {
        var b = new Button();
        return Verify(b).AutoVerify();
    }
}

A solution or workaround

I tracked the problem down to IoHelpers/WriteStream, specifically this line:

await stream.CopyToAsync(targetStream)

Replacing it with

stream.CopyTo(targetStream);

fixes the issue.

@SimonCropp
Copy link
Member

can you submit a pull request with a failing test

@SimonCropp
Copy link
Member

I suspect the problem is vstests use of .GetAwaiter().GetResult() microsoft/testfx#1284

Can you repro in xunit or nunit?

@TymurGubayev
Copy link
Author

TymurGubayev commented Jan 3, 2023

Added a PR with failing test.

Same test in NUnit works just fine.

There is some race condition involved: when stepping through sometimes there is no deadlock.

@SimonCropp
Copy link
Member

i dont think there is anything i can do in the Verify code. even changing await stream.CopyToAsync(targetStream) to be sync would only mitigate the problem. any async code could still deadlock. the only real fix is to make MStest properly respect async by removing the .GetAwaiter().GetResult().

or alternatively you can move to xunit/nunit, or stop using Verify

@TymurGubayev
Copy link
Author

It looks like it's a problem specifically with the combination of MSTest and WinForms, and this StackOverflow answer (pointing to an implementation of WindowsFormsContext) solves the issue.

@Evangelink
Copy link

Hi @TymurGubayev,

I am part of the MSTest team, I am curious to understand if this issue is a randomic issue for you or if that's something that reliably/consistently fails? @SimonCropp PR to fix the issue is awesome but will currently be released in v4. As there are quite some breaking changes related to this update, I'd like to understand if we can follow our roadmap or if we should discuss internally to do an anticipated release.

Thank! And thanks again @SimonCropp .

@TymurGubayev
Copy link
Author

Hi @Evangelink

it fails consistently when I just run the test, just reproduced it on a different machine (source code from TymurGubayev@bb1c111).
But when executing step by step while debugging the test it doesn't always deadlocks.

@SimonCropp
Copy link
Member

given we cant repro. and there is questionable threading in mstests. closing this one for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants