-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix test regression in asyncHelpers.js
- Loading branch information
Showing
2 changed files
with
67 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/harness/asyncHelpers-throwsAsync-func-never-settles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (C) 2024 Julián Espina. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
description: | | ||
assert.throwsAsync returns a promise that never settles if func returns a thenable that never settles. | ||
flags: [async] | ||
includes: [asyncHelpers.js] | ||
---*/ | ||
|
||
var realDone = $DONE; | ||
var doneCalls = 0 | ||
globalThis.$DONE = function () { | ||
doneCalls++; | ||
} | ||
|
||
function delay() { | ||
var later = Promise.resolve(); | ||
for (var i = 0; i < 100; i++) { | ||
later = later.then(); | ||
} | ||
return later; | ||
} | ||
|
||
(async function () { | ||
// Spy on the promise returned by an invocation of assert.throwsAsync | ||
// with a function that returns a thenable which never settles. | ||
var neverSettlingThenable = { then: function () { } }; | ||
const p = assert.throwsAsync(TypeError, function () { return neverSettlingThenable }); | ||
assert(p instanceof Promise, "assert.throwsAsync should return a promise"); | ||
p.then($DONE, $DONE); | ||
})() | ||
// Give it a long time to try. | ||
.then(delay, delay) | ||
.then(function () { | ||
assert.sameValue(doneCalls, 0, "$DONE should not have been called") | ||
}) | ||
.then(realDone, realDone); |