From 4733a56caf108289fc6052dc9c14d8d8839774bf Mon Sep 17 00:00:00 2001 From: Artur Hayrapetyan Date: Fri, 12 Oct 2018 10:35:08 -0700 Subject: [PATCH] test: move tick.js from test/async-hooks to test/common MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport-PR-URL: https://github.com/nodejs/node/pull/23780 PR-URL: https://github.com/nodejs/node/pull/23551 Reviewed-By: Tobias Nießen Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Denys Otrishko Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: Gireesh Punathil Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Trivikram Kamat --- test/async-hooks/test-crypto-pbkdf2.js | 2 +- test/async-hooks/test-crypto-randomBytes.js | 2 +- test/async-hooks/test-embedder.api.async-resource.js | 2 +- test/async-hooks/test-enable-disable.js | 2 +- test/async-hooks/test-fseventwrap.js | 2 +- test/async-hooks/test-fsreqwrap-access.js | 2 +- test/async-hooks/test-fsreqwrap-readFile.js | 2 +- test/async-hooks/test-getaddrinforeqwrap.js | 2 +- test/async-hooks/test-getnameinforeqwrap.js | 2 +- test/async-hooks/test-httpparser.request.js | 2 +- test/async-hooks/test-httpparser.response.js | 2 +- test/async-hooks/test-immediate.js | 2 +- test/async-hooks/test-pipeconnectwrap.js | 2 +- test/async-hooks/test-pipewrap.js | 2 +- test/async-hooks/test-querywrap.js | 2 +- test/async-hooks/test-tcpwrap.js | 2 +- test/async-hooks/test-timers.setTimeout.js | 2 +- test/async-hooks/test-timerwrap.setInterval.js | 2 +- test/async-hooks/test-timerwrap.setTimeout.js | 2 +- test/async-hooks/test-tlswrap.js | 2 +- test/async-hooks/test-ttywrap.readstream.js | 2 +- test/async-hooks/test-ttywrap.writestream.js | 2 +- test/async-hooks/test-udpwrap.js | 2 +- test/common/README.md | 6 ++++++ test/{async-hooks => common}/tick.js | 0 .../test-http2-session-gc-while-write-scheduled.js | 6 +----- test/parallel/test-worker-message-port-transfer-self.js | 8 +------- 27 files changed, 31 insertions(+), 35 deletions(-) rename test/{async-hooks => common}/tick.js (100%) diff --git a/test/async-hooks/test-crypto-pbkdf2.js b/test/async-hooks/test-crypto-pbkdf2.js index ed7270d191e903..4788ce4a580656 100644 --- a/test/async-hooks/test-crypto-pbkdf2.js +++ b/test/async-hooks/test-crypto-pbkdf2.js @@ -7,7 +7,7 @@ if (!common.isMainThread) common.skip('Worker bootstrapping works differently -> different async IDs'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const crypto = require('crypto'); diff --git a/test/async-hooks/test-crypto-randomBytes.js b/test/async-hooks/test-crypto-randomBytes.js index 67f5221a5e0b30..88cd4643ab6638 100644 --- a/test/async-hooks/test-crypto-randomBytes.js +++ b/test/async-hooks/test-crypto-randomBytes.js @@ -7,7 +7,7 @@ if (!common.isMainThread) common.skip('Worker bootstrapping works differently -> different async IDs'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const crypto = require('crypto'); diff --git a/test/async-hooks/test-embedder.api.async-resource.js b/test/async-hooks/test-embedder.api.async-resource.js index 89a889b20192e3..6f71a3e98cbf0f 100644 --- a/test/async-hooks/test-embedder.api.async-resource.js +++ b/test/async-hooks/test-embedder.api.async-resource.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const async_hooks = require('async_hooks'); const { AsyncResource } = async_hooks; diff --git a/test/async-hooks/test-enable-disable.js b/test/async-hooks/test-enable-disable.js index df093da608c29c..c14a125688d0f4 100644 --- a/test/async-hooks/test-enable-disable.js +++ b/test/async-hooks/test-enable-disable.js @@ -85,7 +85,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); diff --git a/test/async-hooks/test-fseventwrap.js b/test/async-hooks/test-fseventwrap.js index 56ada05b760eb6..8608075c822ded 100644 --- a/test/async-hooks/test-fseventwrap.js +++ b/test/async-hooks/test-fseventwrap.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const initHooks = require('./init-hooks'); -const tick = require('./tick'); +const tick = require('../common/tick'); const { checkInvocations } = require('./hook-checks'); const fs = require('fs'); diff --git a/test/async-hooks/test-fsreqwrap-access.js b/test/async-hooks/test-fsreqwrap-access.js index 2b31f2512d6b9c..3a6ce123bd162f 100644 --- a/test/async-hooks/test-fsreqwrap-access.js +++ b/test/async-hooks/test-fsreqwrap-access.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const fs = require('fs'); diff --git a/test/async-hooks/test-fsreqwrap-readFile.js b/test/async-hooks/test-fsreqwrap-readFile.js index 064cd80a48279e..ec58b7d78e81df 100644 --- a/test/async-hooks/test-fsreqwrap-readFile.js +++ b/test/async-hooks/test-fsreqwrap-readFile.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const fs = require('fs'); diff --git a/test/async-hooks/test-getaddrinforeqwrap.js b/test/async-hooks/test-getaddrinforeqwrap.js index bb5bf04849b477..f2a978d7640677 100644 --- a/test/async-hooks/test-getaddrinforeqwrap.js +++ b/test/async-hooks/test-getaddrinforeqwrap.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const dns = require('dns'); diff --git a/test/async-hooks/test-getnameinforeqwrap.js b/test/async-hooks/test-getnameinforeqwrap.js index f0425ee3dc8599..9e06cbf9cbf174 100644 --- a/test/async-hooks/test-getnameinforeqwrap.js +++ b/test/async-hooks/test-getnameinforeqwrap.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const dns = require('dns'); diff --git a/test/async-hooks/test-httpparser.request.js b/test/async-hooks/test-httpparser.request.js index c6e18be5a63d38..7ff99da66c4238 100644 --- a/test/async-hooks/test-httpparser.request.js +++ b/test/async-hooks/test-httpparser.request.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); diff --git a/test/async-hooks/test-httpparser.response.js b/test/async-hooks/test-httpparser.response.js index d56e3e1fecae2d..14a257bf6d6b22 100644 --- a/test/async-hooks/test-httpparser.response.js +++ b/test/async-hooks/test-httpparser.response.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); diff --git a/test/async-hooks/test-immediate.js b/test/async-hooks/test-immediate.js index 3ef782eb5fa66c..7b51902f77cbeb 100644 --- a/test/async-hooks/test-immediate.js +++ b/test/async-hooks/test-immediate.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); diff --git a/test/async-hooks/test-pipeconnectwrap.js b/test/async-hooks/test-pipeconnectwrap.js index df4b8110e67ec4..6c68186e2f239f 100644 --- a/test/async-hooks/test-pipeconnectwrap.js +++ b/test/async-hooks/test-pipeconnectwrap.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); diff --git a/test/async-hooks/test-pipewrap.js b/test/async-hooks/test-pipewrap.js index d4df64d743069e..a632115d228d64 100644 --- a/test/async-hooks/test-pipewrap.js +++ b/test/async-hooks/test-pipewrap.js @@ -5,7 +5,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const { spawn } = require('child_process'); diff --git a/test/async-hooks/test-querywrap.js b/test/async-hooks/test-querywrap.js index 7d71a183130881..f6e7e12e81e9c0 100644 --- a/test/async-hooks/test-querywrap.js +++ b/test/async-hooks/test-querywrap.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const dns = require('dns'); diff --git a/test/async-hooks/test-tcpwrap.js b/test/async-hooks/test-tcpwrap.js index f3100aba0f0aaa..a01a1fc4fe21d4 100644 --- a/test/async-hooks/test-tcpwrap.js +++ b/test/async-hooks/test-tcpwrap.js @@ -6,7 +6,7 @@ if (!common.hasIPv6) common.skip('IPv6 support required'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const net = require('net'); diff --git a/test/async-hooks/test-timers.setTimeout.js b/test/async-hooks/test-timers.setTimeout.js index 8f1d3222ddf662..748fa5565eee64 100644 --- a/test/async-hooks/test-timers.setTimeout.js +++ b/test/async-hooks/test-timers.setTimeout.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const TIMEOUT = common.platformTimeout(100); diff --git a/test/async-hooks/test-timerwrap.setInterval.js b/test/async-hooks/test-timerwrap.setInterval.js index 058f2c9a9d14cc..d2fae953890731 100644 --- a/test/async-hooks/test-timerwrap.setInterval.js +++ b/test/async-hooks/test-timerwrap.setInterval.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const TIMEOUT = 1; diff --git a/test/async-hooks/test-timerwrap.setTimeout.js b/test/async-hooks/test-timerwrap.setTimeout.js index 9c873125d044b6..e633b759773ca7 100644 --- a/test/async-hooks/test-timerwrap.setTimeout.js +++ b/test/async-hooks/test-timerwrap.setTimeout.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const TIMEOUT = common.platformTimeout(100); diff --git a/test/async-hooks/test-tlswrap.js b/test/async-hooks/test-tlswrap.js index 79cf1ab689e997..354cd7ad0cd91d 100644 --- a/test/async-hooks/test-tlswrap.js +++ b/test/async-hooks/test-tlswrap.js @@ -8,7 +8,7 @@ const assert = require('assert'); const fixtures = require('../common/fixtures'); const tls = require('tls'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); diff --git a/test/async-hooks/test-ttywrap.readstream.js b/test/async-hooks/test-ttywrap.readstream.js index 65853da1f7ab17..bf81a3266c1fb6 100644 --- a/test/async-hooks/test-ttywrap.readstream.js +++ b/test/async-hooks/test-ttywrap.readstream.js @@ -4,7 +4,7 @@ const common = require('../common'); const assert = require('assert'); // general hook test setup -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); diff --git a/test/async-hooks/test-ttywrap.writestream.js b/test/async-hooks/test-ttywrap.writestream.js index d8a453e7be2700..44f32e80f015c2 100644 --- a/test/async-hooks/test-ttywrap.writestream.js +++ b/test/async-hooks/test-ttywrap.writestream.js @@ -4,7 +4,7 @@ const common = require('../common'); const assert = require('assert'); // general hook test setup -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); diff --git a/test/async-hooks/test-udpwrap.js b/test/async-hooks/test-udpwrap.js index 5770ac060edce8..0a0e03c5d5148d 100644 --- a/test/async-hooks/test-udpwrap.js +++ b/test/async-hooks/test-udpwrap.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const tick = require('./tick'); +const tick = require('../common/tick'); const initHooks = require('./init-hooks'); const { checkInvocations } = require('./hook-checks'); const dgram = require('dgram'); diff --git a/test/common/README.md b/test/common/README.md index 63b7905113f577..6d86e51d5eb0e8 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -13,6 +13,7 @@ This directory contains modules used to test the Node.js implementation. * [Heap dump checker module](#heap-dump-checker-module) * [HTTP2 module](#http2-module) * [Internet module](#internet-module) +* [tick module](#tick-module) * [tmpdir module](#tmpdir-module) * [WPT module](#wpt-module) @@ -744,6 +745,11 @@ a full `setImmediate()` invocation passes. should not be in scope when `listener.ongc()` is created. +## tick Module + +The `tick` module provides a helper function that can be used to call a callback +after a given number of event loop "ticks". + ## tmpdir Module The `tmpdir` module supports the use of a temporary directory for testing. diff --git a/test/async-hooks/tick.js b/test/common/tick.js similarity index 100% rename from test/async-hooks/tick.js rename to test/common/tick.js diff --git a/test/parallel/test-http2-session-gc-while-write-scheduled.js b/test/parallel/test-http2-session-gc-while-write-scheduled.js index bb23760cebf967..aef9d9571d5559 100644 --- a/test/parallel/test-http2-session-gc-while-write-scheduled.js +++ b/test/parallel/test-http2-session-gc-while-write-scheduled.js @@ -6,6 +6,7 @@ if (!common.hasCrypto) common.skip('missing crypto'); const http2 = require('http2'); const makeDuplexPair = require('../common/duplexpair'); +const tick = require('../common/tick'); // This tests that running garbage collection while an Http2Session has // a write *scheduled*, it will survive that garbage collection. @@ -25,8 +26,3 @@ const makeDuplexPair = require('../common/duplexpair'); global.gc(); }); } - -function tick(n, cb) { - if (n--) setImmediate(tick, n, cb); - else cb(); -} diff --git a/test/parallel/test-worker-message-port-transfer-self.js b/test/parallel/test-worker-message-port-transfer-self.js index c6f29163dfc643..6b8addf0229eac 100644 --- a/test/parallel/test-worker-message-port-transfer-self.js +++ b/test/parallel/test-worker-message-port-transfer-self.js @@ -5,6 +5,7 @@ const common = require('../common'); const assert = require('assert'); const util = require('util'); const { MessageChannel } = require('worker_threads'); +const tick = require('../common/tick'); const { port1, port2 } = new MessageChannel(); @@ -42,10 +43,3 @@ port2.onmessage = common.mustCall((message) => { }); }); port1.postMessage(2); - -function tick(n, cb) { - if (n > 0) - setImmediate(() => tick(n - 1, cb)); - else - cb(); -}