Skip to content

Commit

Permalink
test: use .then(common.mustCall()) for all async IIFEs
Browse files Browse the repository at this point in the history
This makes sure that all async functions finish as expected.

PR-URL: #34363
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
addaleax authored and targos committed Jun 11, 2021
1 parent 55fc206 commit 89ee6ab
Show file tree
Hide file tree
Showing 34 changed files with 54 additions and 60 deletions.
4 changes: 2 additions & 2 deletions test/es-module/test-esm-error-cache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');

const file = '../fixtures/syntax/bad_syntax.mjs';
Expand All @@ -23,4 +23,4 @@ let error;
return true;
}
);
})();
})().then(common.mustCall());
4 changes: 2 additions & 2 deletions test/es-module/test-esm-import-meta-resolve.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Flags: --experimental-import-meta-resolve
import '../common/index.mjs';
import { mustCall } from '../common/index.mjs';
import assert from 'assert';

const dirname = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
Expand All @@ -21,4 +21,4 @@ const fixtures = dirname.slice(0, dirname.lastIndexOf('/', dirname.length - 2) +
assert.strictEqual(await import.meta.resolve('../fixtures/'), fixtures);
assert.strictEqual(await import.meta.resolve('baz/', fixtures),
fixtures + 'node_modules/baz/');
})();
})().then(mustCall());
4 changes: 2 additions & 2 deletions test/internet/test-dns-promises-resolve.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');

const dnsPromises = require('dns').promises;
Expand Down Expand Up @@ -38,5 +38,5 @@ const dnsPromises = require('dns').promises;
const result = await dnsPromises.resolve('example.org', rrtype);
assert.ok(result !== undefined);
assert.ok(result.length > 0);
})();
})().then(common.mustCall());
}
4 changes: 2 additions & 2 deletions test/internet/test-dns-txt-sigsegv.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const dns = require('dns');
const dnsPromises = dns.promises;

(async function() {
const result = await dnsPromises.resolveTxt('www.microsoft.com');
assert.strictEqual(result.length, 0);
})();
})().then(common.mustCall());

dns.resolveTxt('www.microsoft.com', function(err, records) {
assert.strictEqual(err, null);
Expand Down
2 changes: 1 addition & 1 deletion test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,4 +748,4 @@ dns.lookupService('0.0.0.0', 0, common.mustCall());
(async function() {
await dnsPromises.lookup(addresses.INET6_HOST, 6);
await dnsPromises.lookup(addresses.INET_HOST, {});
})();
})().then(common.mustCall());
4 changes: 2 additions & 2 deletions test/parallel/test-c-ares.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const dnsPromises = dns.promises;
res = await dnsPromises.lookup('::1');
assert.strictEqual(res.address, '::1');
assert.strictEqual(res.family, 6);
})();
})().then(common.mustCall());

// Try resolution without hostname.
dns.lookup(null, common.mustSucceed((result, addressType) => {
Expand Down Expand Up @@ -89,5 +89,5 @@ if (!common.isWindows && !common.isIBMi) {

(async function() {
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
})();
})().then(common.mustCall());
}
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawn-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ const expectedResult = tmpdir.path.trim().toLowerCase();
);

assert.deepStrictEqual([...new Set(results)], [expectedResult]);
})();
})().then(common.mustCall());
4 changes: 2 additions & 2 deletions test/parallel/test-dns-lookup-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ async function lookupallNegative() {
lookupNegative(),
lookupallPositive(),
lookupallNegative()
]).then(common.mustCall());
})();
]);
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-dns-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ assert.throws(() => {
all: false
});
assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 });
})();
})().then(common.mustCall());

dns.lookup(false, {
hints: 0,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ dns.lookup('', {
await dnsPromises.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED | dns.ALL
});
})();
})().then(common.mustCall());

{
const err = {
Expand Down Expand Up @@ -447,7 +447,7 @@ assert.throws(() => {
cases.shift();
nextCase();
}));
})();
})().then(common.mustCall());

}));
}
2 changes: 1 addition & 1 deletion test/parallel/test-fs-copyfile-respect-permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function beforeEach() {
const { source, dest, check } = beforeEach();
(async () => {
await assert.rejects(fs.promises.copyFile(source, dest), check);
})();
})().then(common.mustCall());
}

// Test callback API.
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read-empty-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ assert.throws(
'Received Uint8Array(0) []'
}
);
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readdir-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fs.readdir(readdirDir, {
withFileTypes: true
});
assertDirents(dirents);
})();
})().then(common.mustCall());

// Check for correct types when the binding returns unknowns
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-fs-readv-promises.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs').promises;
Expand Down Expand Up @@ -64,4 +63,4 @@ const allocateEmptyBuffers = (combinedLength) => {
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
handle.close();
}
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-fs-rmdir-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function removeAsync(dir) {

// Attempted removal should fail now because the directory is gone.
assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
})();
})().then(common.mustCall());

// Test input validation.
{
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-stat-bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,4 @@ if (!common.isWindows) {
const allowableDelta = Math.ceil(Number(endTime - startTime) / 1e6);
verifyStats(bigintStats, numStats, allowableDelta);
await handle.close();
})();
})().then(common.mustCall());
5 changes: 2 additions & 3 deletions test/parallel/test-fs-writev-promises.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs').promises;
Expand Down Expand Up @@ -48,4 +47,4 @@ tmpdir.refresh();
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
handle.close();
}
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-inspect-publish-uid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { spawnSync } = require('child_process');
await testArg('stderr');
await testArg('http');
await testArg('http,stderr');
})();
})().then(common.mustCall());

async function testArg(argValue) {
console.log('Checks ' + argValue + '..');
Expand Down
8 changes: 3 additions & 5 deletions test/parallel/test-internal-module-wrap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

// Flags: --expose-internals

require('../common');
'use strict';
const common = require('../common');
const assert = require('assert');

const { internalBinding } = require('internal/test/binding');
Expand All @@ -26,4 +24,4 @@ const bar = new ModuleWrap('bar', undefined, 'export const five = 5', 0, 0);

assert.strictEqual(await foo.evaluate(-1, false), undefined);
assert.strictEqual(foo.getNamespace().five, 5);
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ const tcpTests = [
socket.end();
}
common.allowGlobals(...Object.values(global));
})();
})().then(common.mustCall());

function startTCPRepl() {
let resolveSocket, resolveReplServer;
Expand Down
8 changes: 3 additions & 5 deletions test/parallel/test-util-inspect-namespace.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

// Flags: --experimental-vm-modules

require('../common');
'use strict';
const common = require('../common');
const assert = require('assert');

const { SourceTextModule } = require('vm');
Expand All @@ -20,4 +18,4 @@ const { inspect } = require('util');
inspect(m.namespace),
'[Module: null prototype] { a: 1, b: 2 }'
);
})();
})().then(common.mustCall());
4 changes: 2 additions & 2 deletions test/parallel/test-util-promisify.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const stat = promisify(fs.stat);
(async () => {
const value = await promisify(fn)(null, 42);
assert.strictEqual(value, 42);
})();
})().then(common.mustCall());
}

{
Expand Down Expand Up @@ -159,7 +159,7 @@ const stat = promisify(fs.stat);
await fn();
await Promise.resolve();
return assert.strictEqual(stack, err.stack);
})();
})().then(common.mustCall());
}

{
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-util-types.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Flags: --experimental-vm-modules --expose-internals
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const { types, inspect } = require('util');
const vm = require('vm');
Expand Down Expand Up @@ -280,4 +280,4 @@ for (const [ value, _method ] of [
await m.link(() => 0);
await m.evaluate();
assert.ok(types.isModuleNamespaceObject(m.namespace));
})();
})().then(common.mustCall());
8 changes: 4 additions & 4 deletions test/parallel/test-vm-module-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const util = require('util');
baz: 'bar',
typeofProcess: 'undefined'
});
}());
}().then(common.mustCall()));

(async () => {
const m = new SourceTextModule(`
Expand All @@ -45,14 +45,14 @@ const util = require('util');
assert.strictEqual(global.vmResultTypeofProcess, '[object process]');
delete global.vmResultFoo;
delete global.vmResultTypeofProcess;
})();
})().then(common.mustCall());

(async () => {
const m = new SourceTextModule('while (true) {}');
await m.link(common.mustNotCall());
await m.evaluate({ timeout: 500 })
.then(() => assert(false), () => {});
})();
})().then(common.mustCall());

// Check the generated identifier for each module
(async () => {
Expand All @@ -65,7 +65,7 @@ const util = require('util');
assert.strictEqual(m2.identifier, 'vm:module(1)');
const m3 = new SourceTextModule('3', { context: context2 });
assert.strictEqual(m3.identifier, 'vm:module(0)');
})();
})().then(common.mustCall());

// Check inspection of the instance
{
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-vm-module-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,4 @@ const finished = common.mustCall();
await checkInvalidOptionForEvaluate();
checkInvalidCachedData();
finished();
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-vm-module-import-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ async function testInvalid() {
(async () => {
await testBasic();
await testInvalid();
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-vm-module-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ const finished = common.mustCall();
await circular();
await circular2();
finished();
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-vm-module-reevaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ const finished = common.mustCall();
}

finished();
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-vm-module-synthetic.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ const assert = require('assert');
code: 'ERR_VM_MODULE_STATUS',
});
}
})();
})().then(common.mustCall());
4 changes: 2 additions & 2 deletions test/parallel/test-zlib-empty-buffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const zlib = require('zlib');
const { inspect, promisify } = require('util');
const assert = require('assert');
Expand All @@ -23,4 +23,4 @@ const emptyBuffer = Buffer.alloc(0);
`Expected ${inspect(compressed)} to match ${inspect(decompressed)} ` +
`to match for ${method}`);
}
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/sequential/test-inspector-async-call-stack-abort.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (process.argv[2] === 'child') {
await session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 42 });
strictEqual(enabled, 1);
throw new Error(eyecatcher);
})();
})().finally(common.mustCall());
} else {
const { spawnSync } = require('child_process');
const options = { encoding: 'utf8' };
Expand Down
4 changes: 2 additions & 2 deletions test/wasi/test-wasi-stdio.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Flags: --experimental-wasi-unstable-preview1 --experimental-wasm-bigint
'use strict';
require('../common');
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const { strictEqual } = require('assert');
const { closeSync, openSync, readFileSync, writeFileSync } = require('fs');
Expand Down Expand Up @@ -31,4 +31,4 @@ const importObject = { wasi_snapshot_preview1: wasi.wasiImport };
closeSync(stderr);
strictEqual(readFileSync(stdoutFile, 'utf8').trim(), 'x'.repeat(31));
strictEqual(readFileSync(stderrFile, 'utf8').trim(), '');
})();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/wasi/test-wasi-symlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (process.argv[2] === 'wasi-child') {
const { instance } = await WebAssembly.instantiate(buffer, importObject);

wasi.start(instance);
})();
})().then(common.mustCall());
} else {
if (!common.canCreateSymLink()) {
common.skip('insufficient privileges');
Expand Down
2 changes: 1 addition & 1 deletion test/wasi/test-wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (process.argv[2] === 'wasi-child') {
const { instance } = await WebAssembly.instantiate(buffer, importObject);

wasi.start(instance);
})();
})().then(common.mustCall());
} else {
const assert = require('assert');
const cp = require('child_process');
Expand Down

0 comments on commit 89ee6ab

Please sign in to comment.