summaryrefslogtreecommitdiff
path: root/test/pummel
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2020-09-13 09:54:56 -0700
committerRich Trott <rtrott@gmail.com>2020-09-15 10:51:36 -0700
commitae257ca0008cd6d01d477d927fa9962d8f406c5f (patch)
tree1d47f4c130ada00084630ec3dcb364629d7f69b9 /test/pummel
parent26e660f9627f776678106d0afa7da428c44c45cf (diff)
downloadnode-new-ae257ca0008cd6d01d477d927fa9962d8f406c5f.tar.gz
test: improve pummel/test-timers.js
* use Date.now() instead of new Date() because only the timestamp is ever used, so we don't need the full Date object * use separate start times recorded for the two different test cases * improve assertion messages PR-URL: https://github.com/nodejs/node/pull/35175 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Diffstat (limited to 'test/pummel')
-rw-r--r--test/pummel/test-timers.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js
index cd6417abe4..d5d992f7b9 100644
--- a/test/pummel/test-timers.js
+++ b/test/pummel/test-timers.js
@@ -26,10 +26,11 @@ const assert = require('assert');
const WINDOW = 200; // Why does this need to be so big?
-const starttime = new Date();
{
+ const starttime = Date.now();
+
setTimeout(common.mustCall(function() {
- const endtime = new Date();
+ const endtime = Date.now();
const diff = endtime - starttime;
assert.ok(diff > 0);
@@ -46,11 +47,13 @@ const starttime = new Date();
}
{
+ const starttime = Date.now();
+
let interval_count = 0;
setInterval(common.mustCall(function() {
interval_count += 1;
- const endtime = new Date();
+ const endtime = Date.now();
const diff = endtime - starttime;
assert.ok(diff > 0);
@@ -58,9 +61,9 @@ const starttime = new Date();
const t = interval_count * 1000;
- assert.strictEqual(t - WINDOW < diff && diff < t + WINDOW, true);
+ assert.ok(t - WINDOW < diff && diff < t + WINDOW, `t: ${t}`);
- assert.strictEqual(interval_count <= 3, true);
+ assert.ok(interval_count <= 3, `interval_count: ${interval_count}`);
if (interval_count === 3)
clearInterval(this);
}, 3), 1000);