Skip to content

[MTP]: Timeout doesn't abort hanging tests #6776

@cbersch

Description

@cbersch

Describe the bug

With the VSTest-based test execution it was quite easy to add a real™ timeout which could kill hanging tests.
The current --timeout doesn't work in that case.
Using

  • .NET 10 RC2
  • MSTest 4.0.1
  • Windows 11

Steps To Reproduce

Consider the test

[TestClass]
public sealed class TimeoutTests
{
    [TestMethod]
    public void Lock()
    {
        ManualResetEventSlim mre = new(false);
        mre.Wait();
    }
}

with project

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>

  </PropertyGroup>

  <PropertyGroup Condition="'$(UseMtp)' == 'true'">
    <EnableMSTestRunner>true</EnableMSTestRunner>
    <OutputType>Exe</OutputType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MSTest.TestFramework" Version="4.0.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="4.0.1" />
  </ItemGroup>

  <ItemGroup Condition="'$(UseMtp)' != 'true'">
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
  </ItemGroup>
</Project>

and global.json

{
  "test": {
    "runner": "Microsoft.Testing.Platform"
  }
}

MTP

dotnet test --project .\Timeout.csproj --timeout 10s -p:UseMtp=true

runs forever (also Ctrl+C has no effect).

VSTest

Delete the global.json and execute

dotnet test .\Timeout.csproj --blame-hang-timeout=10s

This

  • "nicely" aborts the test run
  • Reports a useful message.
The active test run was aborted. Reason: Test host process crashed

The active Test Run was aborted because the host process exited unexpectedly. Please inspect the call stack above, if available, to get more information about where the exception originated from.
The test running when the crash occurred:
TimeoutTests.Lock

This test may, or may not be the source of the crash.
  Timeout test net10.0 failed with 1 error(s) and 2 warning(s) (12,0s)
    C:\Program Files\dotnet\sdk\10.0.100-rc.2.25502.107\Microsoft.TestPlatform.targets(48,5): warning Data collector 'Blame' message: The specified inactivity time of 10 seconds has elapsed. Collecting hang dumps from testhost and its child processes.
    C:\Program Files\dotnet\sdk\10.0.100-rc.2.25502.107\Microsoft.TestPlatform.targets(48,5): warning Data collector 'Blame' message: Dumping 62032 - testhost.
    C:\temp\mtp_timeout\bin\Debug\net10.0\Timeout.dll : error TESTRUNABORT: Test Run Aborted.
  • Creates a sequence file which contains the executed tests, including the one which was killed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions