Skip to content

Commit 52252bd

Browse files
committed
test(wait): make the wait block test reliable under CPU load
Sometimes load causes the VM to run more slowly, especially with parallel tests. This change allows the wait block a little extra wiggle room to account for that. Ending early is still tested with a fairly strict threshold.
1 parent 840ffb5 commit 52252bd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

test/unit/blocks_control.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ test('wait', t => {
261261
const args = {DURATION: .01};
262262
const waitTime = args.DURATION * 1000;
263263
const startTest = Date.now();
264-
const threshold = 1000 / 60; // 60 hz
264+
const thresholdSmall = 1000 / 60; // only allow the wait to end one 60Hz frame early
265+
const thresholdLarge = 1000 / 3; // be less picky about when the wait ends, in case CPU load makes the VM run slowly
265266
let yields = 0;
266267
const util = new BlockUtility();
267268
const mockUtil = {
@@ -280,15 +281,17 @@ test('wait', t => {
280281
while (timeElapsed < waitTime) {
281282
timeElapsed = mockUtil.stackFrame.timer.timeElapsed();
282283
// In case util.timer is broken - have our own "exit"
283-
if (Date.now() - startTest > timeElapsed + threshold) {
284+
if (Date.now() - startTest > timeElapsed + thresholdSmall) {
284285
break;
285286
}
286287
}
287288

288289
c.wait(args, mockUtil);
289290
t.equal(yields, 1, 'Second call after timeElapsed does not yield');
290291
t.equal(waitTime, mockUtil.stackFrame.duration);
291-
t.ok(timeElapsed >= (waitTime - threshold) &&
292-
timeElapsed <= (waitTime + threshold));
292+
t.ok(timeElapsed >= (waitTime - thresholdSmall),
293+
'Wait block ended too early: ${timeElapsed} < ${waitTime} - ${thresholdSmall}');
294+
t.ok(timeElapsed <= (waitTime + thresholdLarge),
295+
'Wait block ended too late: ${timeElapsed} > ${waitTime} + ${thresholdLarge}');
293296
t.end();
294297
});

0 commit comments

Comments
 (0)