Skip to content

Add TaskRunTestMethod #5932

@Evangelink

Description

@Evangelink

Summary

Add a specialized TestMethodAttribute to run the user code as part of a Task.Run allowing to stop wathching the task in case of timeout.

Background and Motivation

As of today, the TestMethod and derived attributes behavior is changing based on whether or not UseCooperativeCancellation is set to true. This is done to allow some back-compat where MSTest doesn't block if the user doesn't handle the cancellation token correctly in case of a timeout. But this is causing many danling tasks #2433 which can lead to confusions or even errors because the test method is still running.

As part of the effort to simplify the core MSTEst logic and to move each responsability to the right location, it seems more logical that this feature is moved down to a specialized test method attribute.

Proposed Feature

  • Introduce a new attribute to handle the logic on timeout
  • Update the diagnostic recommandign to use cooperative cancellation
  • Update related codefix.

Alternative Designs

None

Metadata

Metadata

Assignees

Labels

Area: MSTestIssues with MSTest that are not specific to more refined area (e.g. analyzers or assertions)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions