Skip to content

Commit acd399f

Browse files
committed
Slow down CPU test
This should reduce the number of random false failures Compensate for slowdown by reducing the number of trials
1 parent e3a0508 commit acd399f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

test/test_cpu_basic.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const assert = require('assert');
2424
const pid = proc.pid;
2525

2626
var time = 0;
27-
const TRIALS = 1000;
27+
const TRIALS = 200;
28+
const MAX_FAILURES = 5;
2829
var failures = 0;
2930
for (let i = 0; i < TRIALS; i++) {
3031
let new_time = ps.cpuTime(pid);
@@ -36,14 +37,14 @@ for (let i = 0; i < TRIALS; i++) {
3637
// And do some extra computation to make sure we get more time.
3738
let v = 1 + Math.random();
3839
let u = '{"a": 1}';
39-
for (let j = 0; j < 1000; j++) {
40-
v = Math.hypot(v, Math.random(), Math.random());
40+
for (let j = 0; j < 10000; j++) {
41+
v = eval("Math.hypot(v, Math.random(), Math.random())");
4142
let c = JSON.parse(u);
4243
c[String.fromCharCode(97 + Math.floor(j * v) % 26)] = v;
4344
u = JSON.stringify(c);
4445
}
4546
}
46-
if (TRIALS * 0.01 < failures) {
47+
if (failures > MAX_FAILURES) {
4748
throw new Error('Too many failures: ' + failures + '/' + TRIALS);
4849
} else {
4950
console.log('Basic CPU time test passed with only ' + failures + '/' + TRIALS + ' failures.');

0 commit comments

Comments
 (0)