From 732620cfe91154d1b821cb1c04ebbfd4c7c44d04 Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Fri, 3 Mar 2017 13:09:19 -0700 Subject: [PATCH] test: remove unneeded tests AsyncWrap will be going through many changes, and the old API will no longer be used. So remove those tests that will no longer be useful. They may be added back later using the new API, once fully implemented. PR-URL: https://github.com/nodejs/node/pull/12892 Ref: https://github.com/nodejs/node/pull/11883 Ref: https://github.com/nodejs/node/pull/8531 Reviewed-By: Andreas Madsen Reviewed-By: Anna Henningsen Reviewed-By: Sam Roberts Reviewed-By: Matteo Collina Reviewed-By: Refael Ackermann Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- .../test-async-wrap-check-providers.js | 122 ------------------ ...st-async-wrap-disabled-propagate-parent.js | 50 ------- .../test-async-wrap-post-did-throw.js | 39 ------ .../test-async-wrap-propagate-parent.js | 49 ------- .../parallel/test-async-wrap-throw-no-init.js | 25 ---- test/parallel/test-async-wrap-uid.js | 63 --------- test/parallel/test-stream-base-no-abort.js | 64 --------- 7 files changed, 412 deletions(-) delete mode 100644 test/parallel/test-async-wrap-check-providers.js delete mode 100644 test/parallel/test-async-wrap-disabled-propagate-parent.js delete mode 100644 test/parallel/test-async-wrap-post-did-throw.js delete mode 100644 test/parallel/test-async-wrap-propagate-parent.js delete mode 100644 test/parallel/test-async-wrap-throw-no-init.js delete mode 100644 test/parallel/test-async-wrap-uid.js delete mode 100644 test/parallel/test-stream-base-no-abort.js diff --git a/test/parallel/test-async-wrap-check-providers.js b/test/parallel/test-async-wrap-check-providers.js deleted file mode 100644 index ed30fa257b89c5..00000000000000 --- a/test/parallel/test-async-wrap-check-providers.js +++ /dev/null @@ -1,122 +0,0 @@ -'use strict'; - -const common = require('../common'); -if (!common.hasCrypto) { - common.skip('missing crypto'); - return; -} - -const assert = require('assert'); -const crypto = require('crypto'); -const dgram = require('dgram'); -const dns = require('dns'); -const fs = require('fs'); -const net = require('net'); -const tls = require('tls'); -const zlib = require('zlib'); -const ChildProcess = require('child_process').ChildProcess; -const StreamWrap = require('_stream_wrap').StreamWrap; -const HTTPParser = process.binding('http_parser').HTTPParser; -const async_wrap = process.binding('async_wrap'); -const pkeys = Object.keys(async_wrap.Providers); - -let keyList = pkeys.slice(); -// Drop NONE -keyList.splice(0, 1); - -// fs-watch currently needs special configuration on AIX and we -// want to improve under https://github.com/nodejs/node/issues/5085. -// strip out fs watch related parts for now -if (common.isAix) { - for (let i = 0; i < keyList.length; i++) { - if ((keyList[i] === 'FSEVENTWRAP') || (keyList[i] === 'STATWATCHER')) { - keyList.splice(i, 1); - } - } -} - -function init(id, provider) { - keyList = keyList.filter((e) => e !== pkeys[provider]); -} - -async_wrap.setupHooks({ init }); - -async_wrap.enable(); - - -setTimeout(common.noop, 1); - -fs.stat(__filename, common.noop); - -if (!common.isAix) { - // fs-watch currently needs special configuration on AIX and we - // want to improve under https://github.com/nodejs/node/issues/5085. - // strip out fs watch related parts for now - fs.watchFile(__filename, common.noop); - fs.unwatchFile(__filename); - fs.watch(__filename).close(); -} - -dns.lookup('localhost', common.noop); -dns.lookupService('::', 0, common.noop); -dns.resolve('localhost', common.noop); - -new StreamWrap(new net.Socket()); - -new (process.binding('tty_wrap').TTY)(); - -crypto.randomBytes(1, common.noop); - -common.refreshTmpDir(); - -net.createServer(function(c) { - c.end(); - this.close(); -}).listen(common.PIPE, function() { - net.connect(common.PIPE, common.noop); -}); - -net.createServer(function(c) { - c.end(); - this.close(checkTLS); -}).listen(0, function() { - net.connect(this.address().port, common.noop); -}); - -dgram.createSocket('udp4').bind(0, function() { - this.send(Buffer.allocUnsafe(2), 0, 2, this.address().port, '::', () => { - this.close(); - }); -}); - -process.on('SIGINT', () => process.exit()); - -// Run from closed net server above. -function checkTLS() { - const options = { - key: fs.readFileSync(`${common.fixturesDir}/keys/ec-key.pem`), - cert: fs.readFileSync(`${common.fixturesDir}/keys/ec-cert.pem`) - }; - const server = tls.createServer(options, common.noop) - .listen(0, function() { - const connectOpts = { rejectUnauthorized: false }; - tls.connect(this.address().port, connectOpts, function() { - this.destroy(); - server.close(); - }); - }); -} - -zlib.createGzip(); - -new ChildProcess(); - -new HTTPParser(HTTPParser.REQUEST); - -process.on('exit', function() { - if (keyList.length !== 0) { - process._rawDebug('Not all keys have been used:'); - process._rawDebug(keyList); - assert.strictEqual(keyList.length, 0); - } -}); diff --git a/test/parallel/test-async-wrap-disabled-propagate-parent.js b/test/parallel/test-async-wrap-disabled-propagate-parent.js deleted file mode 100644 index 65e5eaafa3553a..00000000000000 --- a/test/parallel/test-async-wrap-disabled-propagate-parent.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); -const async_wrap = process.binding('async_wrap'); -const providers = Object.keys(async_wrap.Providers); - -const uidSymbol = Symbol('uid'); - -let cntr = 0; -let client; - -function init(uid, type, parentUid, parentHandle) { - this[uidSymbol] = uid; - - if (parentHandle) { - cntr++; - // Cannot assert in init callback or will abort. - process.nextTick(() => { - assert.strictEqual(providers[type], 'TCPWRAP'); - assert.strictEqual(parentUid, server._handle[uidSymbol], - 'server uid doesn\'t match parent uid'); - assert.strictEqual(parentHandle, server._handle, - 'server handle doesn\'t match parent handle'); - assert.strictEqual(this, client._handle, 'client doesn\'t match context'); - }); - } -} - -async_wrap.setupHooks({ init }); -async_wrap.enable(); - -const server = net.createServer(function(c) { - client = c; - // Allow init callback to run before closing. - setImmediate(() => { - c.end(); - this.close(); - }); -}).listen(0, function() { - net.connect(this.address().port, common.noop); -}); - -async_wrap.disable(); - -process.on('exit', function() { - // init should have only been called once with a parent. - assert.strictEqual(cntr, 1); -}); diff --git a/test/parallel/test-async-wrap-post-did-throw.js b/test/parallel/test-async-wrap-post-did-throw.js deleted file mode 100644 index 35dbfe1378464a..00000000000000 --- a/test/parallel/test-async-wrap-post-did-throw.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -const common = require('../common'); -if (!common.hasCrypto) { - common.skip('missing crypto'); - return; -} - -const assert = require('assert'); -const async_wrap = process.binding('async_wrap'); -let asyncThrows = 0; -let uncaughtExceptionCount = 0; - -process.on('uncaughtException', (e) => { - assert.strictEqual(e.message, 'oh noes!', 'error messages do not match'); -}); - -process.on('exit', () => { - process.removeAllListeners('uncaughtException'); - assert.strictEqual(uncaughtExceptionCount, 1); - assert.strictEqual(uncaughtExceptionCount, asyncThrows); -}); - -function init() { } -function post(id, threw) { - if (threw) - uncaughtExceptionCount++; -} - -async_wrap.setupHooks({ init, post }); -async_wrap.enable(); - -// Timers still aren't supported, so use crypto API. -// It's also important that the callback not happen in a nextTick, like many -// error events in core. -require('crypto').randomBytes(0, () => { - asyncThrows++; - throw new Error('oh noes!'); -}); diff --git a/test/parallel/test-async-wrap-propagate-parent.js b/test/parallel/test-async-wrap-propagate-parent.js deleted file mode 100644 index dbb358ad6ae3c5..00000000000000 --- a/test/parallel/test-async-wrap-propagate-parent.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); -const async_wrap = process.binding('async_wrap'); -const providers = Object.keys(async_wrap.Providers); - -const uidSymbol = Symbol('uid'); - -let cntr = 0; -let client; - -function init(uid, type, parentUid, parentHandle) { - this[uidSymbol] = uid; - - if (parentHandle) { - cntr++; - // Cannot assert in init callback or will abort. - process.nextTick(() => { - assert.strictEqual(providers[type], 'TCPWRAP'); - assert.strictEqual(parentUid, server._handle[uidSymbol], - 'server uid doesn\'t match parent uid'); - assert.strictEqual(parentHandle, server._handle, - 'server handle doesn\'t match parent handle'); - assert.strictEqual(this, client._handle, 'client doesn\'t match context'); - }); - } -} - -async_wrap.setupHooks({ init }); -async_wrap.enable(); - -const server = net.createServer(function(c) { - client = c; - // Allow init callback to run before closing. - setImmediate(() => { - c.end(); - this.close(); - }); -}).listen(0, function() { - net.connect(this.address().port, common.noop); -}); - - -process.on('exit', function() { - // init should have only been called once with a parent. - assert.strictEqual(cntr, 1); -}); diff --git a/test/parallel/test-async-wrap-throw-no-init.js b/test/parallel/test-async-wrap-throw-no-init.js deleted file mode 100644 index 05f453cbcde2c9..00000000000000 --- a/test/parallel/test-async-wrap-throw-no-init.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const common = require('../common'); -const assert = require('assert'); -const async_wrap = process.binding('async_wrap'); - -assert.throws(function() { - async_wrap.setupHooks(null); -}, /first argument must be an object/); - -assert.throws(function() { - async_wrap.setupHooks({}); -}, /init callback must be a function/); - -assert.throws(function() { - async_wrap.enable(); -}, /init callback is not assigned to a function/); - -// Should not throw -async_wrap.setupHooks({ init: common.noop }); -async_wrap.enable(); - -assert.throws(function() { - async_wrap.setupHooks(common.noop); -}, /hooks should not be set while also enabled/); diff --git a/test/parallel/test-async-wrap-uid.js b/test/parallel/test-async-wrap-uid.js deleted file mode 100644 index e28f8537d235c5..00000000000000 --- a/test/parallel/test-async-wrap-uid.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -const common = require('../common'); -const fs = require('fs'); -const assert = require('assert'); -const async_wrap = process.binding('async_wrap'); - -// Give the event loop time to clear out the final uv_close(). -let si_cntr = 3; -process.on('beforeExit', () => { - if (--si_cntr > 0) setImmediate(common.noop); -}); - -const storage = new Map(); -async_wrap.setupHooks({ init, pre, post, destroy }); -async_wrap.enable(); - -function init(uid) { - storage.set(uid, { - init: true, - pre: false, - post: false, - destroy: false, - }); -} - -function pre(uid) { - storage.get(uid).pre = true; -} - -function post(uid) { - storage.get(uid).post = true; -} - -function destroy(uid) { - storage.get(uid).destroy = true; -} - -fs.access(__filename, function(err) { - assert.ifError(err); -}); - -fs.access(__filename, function(err) { - assert.ifError(err); -}); - -async_wrap.disable(); - -process.once('exit', function() { - assert.strictEqual(storage.size, 2); - - for (const item of storage) { - const uid = item[0]; - const value = item[1]; - assert.strictEqual(typeof uid, 'number'); - assert.deepStrictEqual(value, { - init: true, - pre: true, - post: true, - destroy: true, - }); - } -}); diff --git a/test/parallel/test-stream-base-no-abort.js b/test/parallel/test-stream-base-no-abort.js deleted file mode 100644 index 26316065477557..00000000000000 --- a/test/parallel/test-stream-base-no-abort.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; - -const common = require('../common'); -if (!common.hasCrypto) { - common.skip('missing crypto'); - return; -} - -const async_wrap = process.binding('async_wrap'); -const uv = process.binding('uv'); -const assert = require('assert'); -const dgram = require('dgram'); -const fs = require('fs'); -const net = require('net'); -const tls = require('tls'); -const providers = Object.keys(async_wrap.Providers); -let flags = 0; - -// Make sure all asserts have run at least once. -process.on('exit', () => assert.strictEqual(flags, 0b111)); - -function init(id, provider) { - this._external; // Test will abort if nullptr isn't properly checked. - switch (providers[provider]) { - case 'TCPWRAP': - assert.strictEqual(this.fd, uv.UV_EINVAL); - flags |= 0b1; - break; - case 'TLSWRAP': - assert.strictEqual(this.fd, uv.UV_EINVAL); - flags |= 0b10; - break; - case 'UDPWRAP': - assert.strictEqual(this.fd, uv.UV_EBADF); - flags |= 0b100; - break; - } -} - -async_wrap.setupHooks({ init }); -async_wrap.enable(); - -const checkTLS = common.mustCall(function checkTLS() { - const options = { - key: fs.readFileSync(`${common.fixturesDir}/keys/ec-key.pem`), - cert: fs.readFileSync(`${common.fixturesDir}/keys/ec-cert.pem`) - }; - const server = tls.createServer(options, common.noop) - .listen(0, function() { - const connectOpts = { rejectUnauthorized: false }; - tls.connect(this.address().port, connectOpts, function() { - this.destroy(); - server.close(); - }); - }); -}); - -const checkTCP = common.mustCall(function checkTCP() { - net.createServer(common.noop).listen(0, function() { - this.close(checkTLS); - }); -}); - -dgram.createSocket('udp4').close(checkTCP);