Skip to content

Commit 49da459

Browse files
Trottruyadorno
authored andcommitted
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: #35175 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
1 parent 066148d commit 49da459

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

test/pummel/test-timers.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ const assert = require('assert');
2626
const WINDOW = 200; // Why does this need to be so big?
2727

2828

29-
const starttime = new Date();
3029
{
30+
const starttime = Date.now();
31+
3132
setTimeout(common.mustCall(function() {
32-
const endtime = new Date();
33+
const endtime = Date.now();
3334

3435
const diff = endtime - starttime;
3536
assert.ok(diff > 0);
@@ -46,21 +47,23 @@ const starttime = new Date();
4647
}
4748

4849
{
50+
const starttime = Date.now();
51+
4952
let interval_count = 0;
5053

5154
setInterval(common.mustCall(function() {
5255
interval_count += 1;
53-
const endtime = new Date();
56+
const endtime = Date.now();
5457

5558
const diff = endtime - starttime;
5659
assert.ok(diff > 0);
5760
console.error(`diff: ${diff}`);
5861

5962
const t = interval_count * 1000;
6063

61-
assert.strictEqual(t - WINDOW < diff && diff < t + WINDOW, true);
64+
assert.ok(t - WINDOW < diff && diff < t + WINDOW, `t: ${t}`);
6265

63-
assert.strictEqual(interval_count <= 3, true);
66+
assert.ok(interval_count <= 3, `interval_count: ${interval_count}`);
6467
if (interval_count === 3)
6568
clearInterval(this);
6669
}, 3), 1000);

0 commit comments

Comments
 (0)