mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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>
This commit is contained in:
1 parent
4af4a809c2
commit
942551e46f
1 file changed
+8
-5
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user