Skip to content

Commit f510bd2

Browse 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.
1 parent 37d9cfc commit f510bd2

File tree

83 files changed

+451
-354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+451
-354
lines changed
Lines 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());

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

Lines 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
});

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

Lines 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);

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

Lines 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
}));

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

Lines 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() {

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

Lines 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');

test/async-hooks/test-promise.js

Lines 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');

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

Lines 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');

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

Lines 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' });

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

Lines 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)