Skip to content

Commit 7f2a6b7

Browse files
Fixes to vCPU-ms test (#1183)
Fixes and tweaks for the get-vcpu-ms test, which was failing in CI for the unrelated PR #1182. - **Use more verbose failure in get-vcpu-ms test**, so we know which assertion failed - **Formatting fixes**, because I don't know JS style - **Fix spacing around truthy debug message**, because it put the space in the wrong place - **Weaken assertion around vCPU startup time: >=0, not >0**, because apparently the runtime's startup is so good now that this assertion fails
1 parent 5baaa01 commit 7f2a6b7

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

integration-tests/js-compute/fixtures/app/src/assertions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export { assert as strictEqual };
5555
export function ok(truthy, code) {
5656
if (!truthy) {
5757
throw new Error(
58-
`Expected ${code ? ' ' + code : ''}to be truthy - Found \`${JSON.stringify(prettyPrintSymbol(truthy))}\``,
58+
`Expected ${code ? code + ' ' : ''}to be truthy - Found \`${JSON.stringify(prettyPrintSymbol(truthy))}\``,
5959
);
6060
}
6161
}

integration-tests/js-compute/fixtures/app/src/compute.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import { purgeSurrogateKey, vCpuTime } from 'fastly:compute';
55
routes.set('/compute/get-vcpu-ms', () => {
66
const cpuTime = vCpuTime();
77
strictEqual(typeof cpuTime, 'number');
8-
ok(cpuTime > 0);
9-
ok(cpuTime < 3000);
8+
// We can't assert > 0; this only claims millisecond resolution,
9+
// and we hopefully spent less than 500us starting.
10+
ok(cpuTime >= 0, 'cpuTime >= 0');
11+
ok(cpuTime < 3000, 'cputime < 3000');
1012
const arr = new Array(100_000).fill(1);
1113
for (let j = 1; j < 100; j++) {
1214
for (let i = 1; i < 100_000; i++) {
1315
arr[i] = (arr[i] + arr[i - 1] + i) / 3;
1416
}
1517
}
1618
const cpuTime2 = vCpuTime();
17-
ok(cpuTime2 > cpuTime);
18-
ok(cpuTime2 - cpuTime > 1);
19+
ok(cpuTime2 > cpuTime, 'cpuTime2 > cpuTime');
20+
ok(cpuTime2 - cpuTime > 1, 'cpuTime2 - cpuTime > 1');
1921
return pass('ok');
2022
});
2123

0 commit comments

Comments
 (0)