summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2018-09-13 07:35:15 -0700
committerRich Trott <rtrott@gmail.com>2018-10-17 20:38:07 -0700
commite7af9830e98fcda7e7a11e0b13b667163cc8c940 (patch)
treebf90f7e9823fe29f90ea9b890ec39370a3e97526 /test/parallel
parent4e9e0d339efa46316d90d6f2618afd0c0fc6cd34 (diff)
downloadandroid-node-v8-e7af9830e98fcda7e7a11e0b13b667163cc8c940.tar.gz
android-node-v8-e7af9830e98fcda7e7a11e0b13b667163cc8c940.tar.bz2
android-node-v8-e7af9830e98fcda7e7a11e0b13b667163cc8c940.zip
timers: run nextTicks after each immediate and timer
In order to better match the browser behaviour, run nextTicks (and subsequently the microtask queue) after each individual Timer and Immediate, rather than after the whole list is processed. The current behaviour is somewhat of a performance micro-optimization and also partly dictated by how timer handles were implemented. PR-URL: https://github.com/nodejs/node/pull/22842 Fixes: https://github.com/nodejs/node/issues/22257 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-process-fatal-exception-tick.js26
-rw-r--r--test/parallel/test-repl-underscore.js2
-rw-r--r--test/parallel/test-timers-immediate-queue.js9
-rw-r--r--test/parallel/test-timers-next-tick.js27
4 files changed, 27 insertions, 37 deletions
diff --git a/test/parallel/test-process-fatal-exception-tick.js b/test/parallel/test-process-fatal-exception-tick.js
deleted file mode 100644
index f22273e01c..0000000000
--- a/test/parallel/test-process-fatal-exception-tick.js
+++ /dev/null
@@ -1,26 +0,0 @@
-'use strict';
-
-const common = require('../common');
-const assert = require('assert');
-
-if (!common.isMainThread)
- common.skip('Error handling timing is different in Workers');
-
-// If a process encounters an uncaughtException, it should schedule
-// processing of nextTicks on the next Immediates cycle but not
-// before all Immediates are handled
-
-let stage = 0;
-
-process.once('uncaughtException', common.expectsError({
- type: Error,
- message: 'caughtException'
-}));
-
-setImmediate(() => {
- stage++;
- process.nextTick(() => assert.strictEqual(stage, 2));
-});
-setTimeout(() => setImmediate(() => stage++), 1);
-common.busyLoop(10);
-throw new Error('caughtException');
diff --git a/test/parallel/test-repl-underscore.js b/test/parallel/test-repl-underscore.js
index dea2ed4370..7e7cabeda7 100644
--- a/test/parallel/test-repl-underscore.js
+++ b/test/parallel/test-repl-underscore.js
@@ -195,8 +195,6 @@ function testError() {
/setImmediate/,
/^ at/,
/^ at/,
- /^ at/,
- /^ at/,
];
for (const line of lines) {
const expected = expectedLines.shift();
diff --git a/test/parallel/test-timers-immediate-queue.js b/test/parallel/test-timers-immediate-queue.js
index ba9ba87c40..dd793eead0 100644
--- a/test/parallel/test-timers-immediate-queue.js
+++ b/test/parallel/test-timers-immediate-queue.js
@@ -33,11 +33,14 @@ const assert = require('assert');
let ticked = false;
let hit = 0;
-const QUEUE = 1000;
+const QUEUE = 10;
function run() {
- if (hit === 0)
- process.nextTick(function() { ticked = true; });
+ if (hit === 0) {
+ setTimeout(() => { ticked = true; }, 1);
+ const now = Date.now();
+ while (Date.now() - now < 2);
+ }
if (ticked) return;
diff --git a/test/parallel/test-timers-next-tick.js b/test/parallel/test-timers-next-tick.js
index 1db1d18c3a..89ebf6c8c1 100644
--- a/test/parallel/test-timers-next-tick.js
+++ b/test/parallel/test-timers-next-tick.js
@@ -2,14 +2,29 @@
const common = require('../common');
-// This test documents an internal implementation detail of the Timers:
-// since timers of different durations are stored in separate lists,
-// a nextTick queue will clear after each list of timers. While this
-// behaviour is not documented it could be relied on by Node's users.
+// This test verifies that the next tick queue runs after each
+// individual Timeout, as well as each individual Immediate.
setTimeout(common.mustCall(() => {
- process.nextTick(() => { clearTimeout(t2); });
+ process.nextTick(() => {
+ // Confirm that clearing Timeouts from a next tick doesn't explode.
+ clearTimeout(t2);
+ clearTimeout(t3);
+ });
}), 1);
-const t2 = setTimeout(common.mustNotCall(), 2);
+const t2 = setTimeout(common.mustNotCall(), 1);
+const t3 = setTimeout(common.mustNotCall(), 1);
+setTimeout(common.mustCall(), 1);
common.busyLoop(5);
+
+setImmediate(common.mustCall(() => {
+ process.nextTick(() => {
+ // Confirm that clearing Immediates from a next tick doesn't explode.
+ clearImmediate(i2);
+ clearImmediate(i3);
+ });
+}));
+const i2 = setImmediate(common.mustNotCall());
+const i3 = setImmediate(common.mustNotCall());
+setImmediate(common.mustCall());