Skip to content

Timeout diagnostics lose the promise a hung test awaits once it is garbage-collected #217

Closed

Description

@YevheniiKotyrlo

Describe the bug

When a test or a beforeAll / afterAll hook times out, its error lists the promises it created that are still pending. Since #143 the tracker drops a promise's record as soon as a FinalizationRegistry reports the promise collected. A promise nobody can resolve, await new Promise(() => {}) being the usual cause of a hang, is unreachable while the test waits on it, so a garbage collection inside the timeout window removes the one record the diagnostics exist to show.

runner-context.test.ts's two timeout cases assert that record, and they fail at random:

-         "items": ArrayContaining [
-           ObjectContaining {
-             "stack": StringContaining "Promise created",
-           },
-         ],
+         "items": [],

On a Windows host runner-context.test.ts failed 2 of 12 runs of main this way.

I have a fix that keeps the record of a collected promise while the test or hook that created it can still time out, and releases it when that window closes. I can open a PR.

System Info

System:
  OS: Windows 11 10.0.26200
Binaries:
  Node: 26.8.1

React Native Harness Version

1.6.0 (main at bca0781)

Reproduction

https://github.com/callstackincubator/react-native-harness/blob/main/packages/runtime/src/__tests__/runner-context.test.ts

Steps to reproduce

  1. Run pnpm exec vitest run src/__tests__/runner-context.test.ts in packages/runtime a few times.
  2. "fails the suite when beforeAll times out and skips its tests" or "fails the timed-out test and skips the rest of the file" fails now and then with "items": [].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions