Skip to content

Detect hanging async operations #3119

@cyco130

Description

@cyco130

Clear and concise description of the problem

As a developer using Vitest I want to be able to detect if an async operation that was started during a test case hasn't completed at the end of that test so that I can catch hanging promise bugs. I am willing to contribute a PR if there is interest.

Suggested solution

We could provide a --detect-async-leaks flag to turn on this type of detection. Node.js's builtin async_hooks module provides the necessary functionality

Alternative

Alternatively, we could make this the default and provide an option to turn it off.

Additional context

For example in Deno the following test fails with the message "Test case is leaking async ops":

Deno.test("hanging interval", () => {
  setInterval(() => {}, 1000);
});

This helped me catch a few particularly hard to find bugs in a streaming form data parser I was working on. Web streams are particularly prone to this type of error but there are many other cases where such detection would be useful.

Validations

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Approved

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions