1
0
Fork 0
mirror of synced 2024-09-11 06:56:23 +12:00

Fix server tests.

This commit is contained in:
Sam Rose 2024-01-24 16:18:56 +00:00
parent 1c3069178f
commit cc363f1ba7
No known key found for this signature in database
2 changed files with 9 additions and 2 deletions

View file

@ -12,6 +12,13 @@ const helpersSource = fs.readFileSync(
"utf8" "utf8"
) )
class ExecutionTimeoutError extends Error {
constructor(message: string) {
super(message)
this.name = "ExecutionTimeoutError"
}
}
export function init() { export function init() {
setJSRunner((js: string, ctx: Record<string, any>) => { setJSRunner((js: string, ctx: Record<string, any>) => {
return tracer.trace("runJS", {}, span => { return tracer.trace("runJS", {}, span => {
@ -91,7 +98,7 @@ export function init() {
if (perRequestLimit) { if (perRequestLimit) {
const cpuMs = Number(jsIsolate.cpuTime) / 1e6 const cpuMs = Number(jsIsolate.cpuTime) / 1e6
if (cpuMs > perRequestLimit) { if (cpuMs > perRequestLimit) {
throw new Error( throw new ExecutionTimeoutError(
`CPU time limit exceeded (${cpuMs}ms > ${perRequestLimit}ms)` `CPU time limit exceeded (${cpuMs}ms > ${perRequestLimit}ms)`
) )
} }

View file

@ -56,7 +56,7 @@ module.exports.processJS = (handlebars, context) => {
const res = { data: runJS(js, sandboxContext) } const res = { data: runJS(js, sandboxContext) }
return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}` return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}`
} catch (error) { } catch (error) {
if (error.code === "ERR_SCRIPT_EXECUTION_TIMEOUT") { if (error.message === "Script execution timed out.") {
return "Timed out while executing JS" return "Timed out while executing JS"
} }
if (error.name === "ExecutionTimeoutError") { if (error.name === "ExecutionTimeoutError") {