CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.06k stars 299 forks source link

Microsoft.Toolkit.Mvvm v7.1.1 will freeze NUnit tests #14

Closed jozefizso closed 3 years ago

jozefizso commented 3 years ago

Describe the bug

After upgrading Microsoft.Toolkit.Mvvm to v7.1.1 from v7.0.2 out unit tests are failing because their freeze after executing every test in the project. We use NUnit 4 to run tests. The problem is reproducible locally and on Azure Pipelines build machines.

Steps to Reproduce

We don't have a sample app as this is a proprietary software. We have application which uses Microsoft.Toolkit.Mvvm package and we have another unit tests project using NUnit.

Steps to reproduce the behavior:

  1. Upgrading Microsoft.Toolkit.Mvvm to v7.1.1
  2. Run unit tests using Visual Studio Test Explorer
  3. Wait for tests to finish.

Observe all tests were finished but Test Explorer reports tests are still running. This error is logged in the console:

Exception NUnit.Engine.NUnitEngineUnloadException,    Exception thrown unloading tests from C:\dev\ProjectA\tests\ProjectA.Tests\bin\Debug\ProjectA.Tests.dll
Unable to unload application domain: unload thread timed out after 30 seconds.
Application domain was unloaded before all details could be read.

   at NUnit.Engine.Services.DomainManager.DomainUnloader.Unload()
   at NUnit.Engine.Runners.TestDomainRunner.UnloadPackage()
   at NUnit.Engine.Runners.AbstractTestRunner.Unload()
   at NUnit.Engine.Runners.MasterTestRunner.UnloadPackage()
   at NUnit.Engine.Runners.MasterTestRunner.Unload()
   at NUnit.VisualStudio.TestAdapter.NUnitEngine.NUnitEngineAdapter.CloseRunner() in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitEngine\NUnitEngineAdapter.cs:line 128
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath, IGrouping`2 testCases, TestFilter filter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 305
NUnit Adapter 4.0.0.0: Test execution complete
An exception occurred while invoking executor 'executor://nunit3testexecutor/': Exception encountered unloading application domain
Stack trace:
   at NUnit.Engine.Services.DomainManager.DomainUnloader.Unload()
   at NUnit.Engine.Runners.TestDomainRunner.UnloadPackage()
   at NUnit.Engine.Runners.AbstractTestRunner.Unload()
   at NUnit.Engine.Runners.MasterTestRunner.UnloadPackage()
   at NUnit.Engine.Runners.MasterTestRunner.Unload()
   at NUnit.VisualStudio.TestAdapter.NUnitEngine.NUnitEngineAdapter.CloseRunner() in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitEngine\NUnitEngineAdapter.cs:line 128
   at NUnit.VisualStudio.TestAdapter.NUnitEngine.NUnitEngineAdapter.Dispose() in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitEngine\NUnitEngineAdapter.cs:line 132
   at NUnit.VisualStudio.TestAdapter.NUnitTestAdapter.Unload() in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitTestAdapter.cs:line 320
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 205
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithTests.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUri, RunContext runContext, IFrameworkHandle frameworkHandle)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.<>c__DisplayClass48_0.<RunTestInternalWithExecutors>b__0()
   at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.<>c__DisplayClass0_0.<Run>b__0()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.Run(Action action, PlatformApartmentState apartmentState, Boolean waitForCompletion)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.TryToRunInSTAThread(Action action, Boolean waitForCompletion)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)

Inner exception: Exception encountered unloading application domain: Attempted to access an unloaded appdomain. (Exception from HRESULT: 0x80131014)
Application domain was unloaded before all details could be read.

Expected behavior

There should be no errors when NUnit tries to unload the app domain.

Environment

NuGet Package(s): 7.1.1

Windows 10 Build Number:

App min and target version:

Device form factor:

Visual Studio version:

ghost commented 3 years ago

Hello jozefizso, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback πŸ™Œ

michael-hawker commented 3 years ago

FYI @Sergio0694

Sergio0694 commented 3 years ago

@jozefizso Are your tests running on .NET Framework? If so, this is a known issue (seems the same as CommunityToolkit/dotnet#12), which I have fixed already (not in this repo). @michael-hawker We might want to consider pushing another hotfix with this πŸ€”

For future reference: we would need to cherry pick e2b336184f51fcd755f3151222ff948176ee954c from the new repo.

michael-hawker commented 3 years ago

@Sergio0694 I know we discussed just releasing an update from the new repo with some other fixes, so may be best to use that as a test maybe? Let's talk about it more at the start of next week after .NET Conf?

jozefizso commented 3 years ago

@Sergio0694 yes, we use .NET Framework 4.6.2. We run VSTest with NUnit runner 4.

Sergio0694 commented 3 years ago

Closing this was e2b336184f51fcd755f3151222ff948176ee954c fixed it, it will be available in a future release 😊