Skip to content

Promise.reject + setTimeout causes async test failure #62412

@Fordi

Description

@Fordi

Version

v24.13.1

Platform

Linux Federation 6.17.0-19-generic #19~24.04.2-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 6 23:08:46 UTC 2 x86_64 x86_64 x86_64 GNU/Linux 

Subsystem

node:timers/promises; node:test; node:assert

What steps will reproduce the bug?

The following test always fails:

./Trivial.test.js

"use strict"; const { setTimeout } = require("node:timers/promises"); const { test } = require("node:test"); const { fail } = require("node:assert"); test("Trivial test", async () => { const badPromise = Promise.reject("bad value"); console.debug("Promise created"); await setTimeout(100); console.debug("Timeout awaited"); try { console.debug("Awaiting promise"); await badPromise; fail("should not resolve"); } catch (error) { console.debug("Task failed successfully:", error); } });

How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior? Why is that the expected behavior?

The trivial test should pass.

What do you see instead?

Trivial test runs fully, but reports as having failed before its execution ends, despite the rejected promise being awaited within a try/catch block.

output:

Fordi@the-laptop:~/develop/trivial-failure$ node --test Trivial.test.js Promise created ✖ Trivial test (4.506174ms) Timeout awaited Awaiting promise Task failed successfully: bad value (node:276399) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1) (Use `node --trace-warnings ...` to show where the warning was created) ℹ tests 1 ℹ suites 0 ℹ pass 0 ℹ fail 1 ℹ cancelled 0 ℹ skipped 0 ℹ todo 0 ℹ duration_ms 173.199305 ✖ failing tests: test at Trivial.test.js:7:1 ✖ Trivial test (4.506174ms) 'bad value' 

Additional information

This situation is based on a Jasmine test that fails but also, doesn't make it past the console.debug("Promise created"); line, flatly exiting at the same time the native testing version reports a failed test. That's in node v20.20.0.

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