Skip to content

Fixes to vCPU-ms test #1183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export { assert as strictEqual };
export function ok(truthy, code) {
if (!truthy) {
throw new Error(
`Expected ${code ? ' ' + code : ''}to be truthy - Found \`${JSON.stringify(prettyPrintSymbol(truthy))}\``,
`Expected ${code ? code + ' ' : ''}to be truthy - Found \`${JSON.stringify(prettyPrintSymbol(truthy))}\``,
);
}
}
Expand Down
10 changes: 6 additions & 4 deletions integration-tests/js-compute/fixtures/app/src/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { purgeSurrogateKey, vCpuTime } from 'fastly:compute';
routes.set('/compute/get-vcpu-ms', () => {
const cpuTime = vCpuTime();
strictEqual(typeof cpuTime, 'number');
ok(cpuTime > 0);
ok(cpuTime < 3000);
// We can't assert > 0; this only claims millisecond resolution,
// and we hopefully spent less than 500us starting.
ok(cpuTime >= 0, 'cpuTime >= 0');
ok(cpuTime < 3000, 'cputime < 3000');
const arr = new Array(100_000).fill(1);
for (let j = 1; j < 100; j++) {
for (let i = 1; i < 100_000; i++) {
arr[i] = (arr[i] + arr[i - 1] + i) / 3;
}
}
const cpuTime2 = vCpuTime();
ok(cpuTime2 > cpuTime);
ok(cpuTime2 - cpuTime > 1);
ok(cpuTime2 > cpuTime, 'cpuTime2 > cpuTime');
ok(cpuTime2 - cpuTime > 1, 'cpuTime2 - cpuTime > 1');
return pass('ok');
});

Expand Down
Loading