Fix server tests.
This commit is contained in:
parent
1c3069178f
commit
cc363f1ba7
|
@ -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)`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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") {
|
||||||
|
|
Loading…
Reference in New Issue