Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a49d543

Browse filesBrowse files
committed
test: enforce better never-settling-promise detection
Tests should be explicit regarding whether a promise is expected to settle, and the test should fail when the behavior does not meet expectations. PR-URL: #60976 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
1 parent 41adb54 commit a49d543
Copy full SHA for a49d543

83 files changed

+451-354Lines changed: 451 additions & 354 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
'use strict';
22

33
const common = require('../../common');
4-
const assert = require('assert');
54
const { testResolveAsync } = require(`./build/${common.buildType}/binding`);
65

76
// Checks that resolving promises from C++ works.
87

9-
let called = false;
10-
testResolveAsync().then(() => { called = true; });
11-
12-
process.on('beforeExit', common.mustCall(() => { assert(called); }));
8+
testResolveAsync().then(common.mustCall());
Collapse file

‎test/async-hooks/test-async-local-storage-errors.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-async-local-storage-errors.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function fireErr5() {
106106
const makeOrphan = vm.compileFunction(`(${String(() => {
107107
async function main() {
108108
await null;
109+
// eslint-disable-next-line node-core/must-call-assert
109110
Promise.resolve().then(() => {
110111
throw new Error('err5');
111112
});
Collapse file

‎test/async-hooks/test-async-local-storage-promises.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-async-local-storage-promises.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ async function main() {
1111
assert.strictEqual(asyncLocalStorage.getStore().get('a'), 1);
1212
throw err;
1313
});
14-
await assert.rejects(new Promise((resolve, reject) => {
14+
await assert.rejects(new Promise((resolve) => {
1515
asyncLocalStorage.run(new Map(), () => {
1616
const store = asyncLocalStorage.getStore();
1717
store.set('a', 1);
18-
next().then(resolve, reject);
18+
resolve(next());
1919
});
2020
}), err);
2121
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
Collapse file

‎test/async-hooks/test-async-local-storage-thenable.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-async-local-storage-thenable.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ store.run(data, common.mustCall(() => {
4848
// Returning a thenable in a then handler
4949
store.run(data, common.mustCall(() => {
5050
assert.strictEqual(store.getStore(), data);
51-
Promise.resolve().then(() => thenable());
51+
Promise.resolve().then(() => thenable()).then(common.mustCall());
5252
assert.strictEqual(store.getStore(), data);
5353
}));
Collapse file

‎test/async-hooks/test-destroy-not-blocked.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-destroy-not-blocked.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ function testPromise() {
6464
assert.strictEqual(activeId, res.asyncId());
6565
res.emitDestroy();
6666
// Promise has higher prio than emit destroy
67-
Promise.resolve().then(common.mustCall(() =>
68-
assert.strictEqual(activeId, res.asyncId())),
69-
);
67+
Promise.resolve().then(common.mustCall(() => {
68+
assert.strictEqual(activeId, res.asyncId());
69+
}));
7070
}
7171

7272
async function testAwait() {
Collapse file

‎test/async-hooks/test-promise.chain-promise-before-init-hooks.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-promise.chain-promise-before-init-hooks.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const p = new Promise(common.mustCall(function executor(resolve) {
1717
p.then(function afterResolution(val) {
1818
assert.strictEqual(val, 5);
1919
return val;
20-
});
20+
}).then(common.mustCall());
2121

2222
// Init hooks after chained promise is created
2323
const hooks = initHooks();
@@ -34,7 +34,7 @@ process.on('exit', function onexit() {
3434
const as = hooks.activitiesOfTypes('PROMISE');
3535
const unknown = hooks.activitiesOfTypes('Unknown');
3636
assert.strictEqual(as.length, 0);
37-
assert.strictEqual(unknown.length, 1);
37+
assert.strictEqual(unknown.length, 2);
3838

3939
const a0 = unknown[0];
4040
assert.strictEqual(a0.type, 'Unknown');
Collapse file

‎test/async-hooks/test-promise.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-promise.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const hooks = initHooks();
1616
hooks.enable();
1717

1818
const p = new Promise(common.mustCall(executor));
19-
p.then(function afterResolution(val) {
19+
p.then(common.mustCall(function afterResolution(val) {
2020
assert.strictEqual(val, 5);
2121
const as = hooks.activitiesOfTypes('PROMISE');
2222
assert.strictEqual(as.length, 2);
2323
checkInvocations(as[0], { init: 1 }, 'after resolution parent promise');
2424
checkInvocations(as[1], { init: 1, before: 1 },
2525
'after resolution child promise');
26-
});
26+
}));
2727

2828
function executor(resolve) {
2929
const as = hooks.activitiesOfTypes('PROMISE');
Collapse file

‎test/async-hooks/test-promise.promise-before-init-hooks.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-promise.promise-before-init-hooks.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ hooks.enable();
1616
p.then(function afterResolution(val) {
1717
assert.strictEqual(val, 5);
1818
const as = hooks.activitiesOfTypes('PROMISE');
19-
assert.strictEqual(as.length, 1);
19+
assert.strictEqual(as.length, 2);
2020
checkInvocations(as[0], { init: 1, before: 1 },
2121
'after resolution child promise');
2222
return val;
23-
});
23+
}).then(common.mustCall());
2424

2525
process.on('exit', function onexit() {
2626
hooks.disable();
2727
hooks.sanityCheck('PROMISE');
2828

2929
const as = hooks.activitiesOfTypes('PROMISE');
30-
assert.strictEqual(as.length, 1);
30+
assert.strictEqual(as.length, 2);
3131

3232
const a0 = as[0];
3333
assert.strictEqual(a0.type, 'PROMISE');
Collapse file

‎test/client-proxy/test-http-proxy-request-max-sockets.mjs‎

Copy file name to clipboardExpand all lines: test/client-proxy/test-http-proxy-request-max-sockets.mjs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const server = http.createServer(common.mustCall((req, res) => {
2020
console.log('Responding to /first');
2121
res.writeHead(200, { 'Content-Type': 'text/plain' });
2222
res.end('Response for /first');
23-
});
23+
}).then(common.mustCall());
2424
} else if (req.url === '/second') {
2525
// Respond immediately for the second request
2626
res.writeHead(200, { 'Content-Type': 'text/plain' });
Collapse file

‎test/client-proxy/test-https-proxy-request-max-sockets.mjs‎

Copy file name to clipboardExpand all lines: test/client-proxy/test-https-proxy-request-max-sockets.mjs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const server = https.createServer({
3131
console.log('Responding to /first');
3232
res.writeHead(200, { 'Content-Type': 'text/plain' });
3333
res.end('Response for /first');
34-
});
34+
}).then(common.mustCall());
3535
} else if (req.url === '/second') {
3636
// Respond immediately for the second request
3737
res.writeHead(200, { 'Content-Type': 'text/plain' });

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.