summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorJeremiah Senkpiel <fishrock123@rocketmail.com>2018-12-03 17:41:58 -0800
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2019-01-28 16:25:07 -0800
commita7c66b6aaeb8132540abee12ffa9ac1c1fa2f373 (patch)
tree564283992698f1a73604169deb15d458041565d7 /test/parallel
parenta0419dd8ca66733e7a4592d98d4f4ebe2f2762e3 (diff)
downloadandroid-node-v8-a7c66b6aaeb8132540abee12ffa9ac1c1fa2f373.tar.gz
android-node-v8-a7c66b6aaeb8132540abee12ffa9ac1c1fa2f373.tar.bz2
android-node-v8-a7c66b6aaeb8132540abee12ffa9ac1c1fa2f373.zip
timers: truncate decimal values
Reverts some timers behavior back to as it was before 2930bd1317d15d12738a4896c0a6c05700411b47 That commit introduced an unintended change which allowed non-integer timeouts to actually exist since the value is no longer converted to an integer via a TimeWrap handle directly. Even with the fix in e9de43549843da9f4f081cce917945878967df7 non-integer timeouts are still indeterministic, because libuv does not support them. This fixes the issue by emulating the old behavior: truncate the `_idleTimeout` before using it. See comments in https://github.com/nodejs/node/pull/24214 for more background on this. PR-URL: https://github.com/nodejs/node/pull/24819 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-timers-non-integer-delay.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/parallel/test-timers-non-integer-delay.js b/test/parallel/test-timers-non-integer-delay.js
index 017ef28d0f..a57922e3c7 100644
--- a/test/parallel/test-timers-non-integer-delay.js
+++ b/test/parallel/test-timers-non-integer-delay.js
@@ -21,6 +21,7 @@
'use strict';
const common = require('../common');
+const assert = require('assert');
/*
* This test makes sure that non-integer timer delays do not make the process
@@ -47,3 +48,37 @@ const interval = setInterval(common.mustCall(() => {
process.exit(0);
}
}, N), TIMEOUT_DELAY);
+
+// Test non-integer delay ordering
+{
+ const ordering = [];
+
+ setTimeout(common.mustCall(() => {
+ ordering.push(1);
+ }), 1);
+
+ setTimeout(common.mustCall(() => {
+ ordering.push(2);
+ }), 1.8);
+
+ setTimeout(common.mustCall(() => {
+ ordering.push(3);
+ }), 1.1);
+
+ setTimeout(common.mustCall(() => {
+ ordering.push(4);
+ }), 1);
+
+ setTimeout(common.mustCall(() => {
+ const expected = [1, 2, 3, 4];
+
+ assert.deepStrictEqual(
+ ordering,
+ expected,
+ `Non-integer delay ordering should be ${expected}, but got ${ordering}`
+ );
+
+ // 2 should always be last of these delays due to ordering guarentees by
+ // the implementation.
+ }), 2);
+}