Make tests faster and more robust.
This commit is contained in:
parent
1c34147357
commit
c25963bc6f
|
@ -2089,9 +2089,7 @@ describe.each([
|
|||
|
||||
describe("Formula JS protection", () => {
|
||||
it("should time out JS execution if a single cell takes too long", async () => {
|
||||
await config.withEnv(
|
||||
{ JS_PER_EXECUTION_TIME_LIMIT_MS: 100 },
|
||||
async () => {
|
||||
await config.withEnv({ JS_PER_EXECUTION_TIME_LIMIT_MS: 20 }, async () => {
|
||||
const js = Buffer.from(
|
||||
`
|
||||
let i = 0;
|
||||
|
@ -2125,15 +2123,14 @@ describe.each([
|
|||
const row = rows[0]
|
||||
expect(row.text).toBe("foo")
|
||||
expect(row.formula).toBe("Timed out while executing JS")
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
it("should time out JS execution if a multiple cells take too long", async () => {
|
||||
await config.withEnv(
|
||||
{
|
||||
JS_PER_EXECUTION_TIME_LIMIT_MS: 100,
|
||||
JS_PER_REQUEST_TIME_LIMIT_MS: 200,
|
||||
JS_PER_EXECUTION_TIME_LIMIT_MS: 20,
|
||||
JS_PER_REQUEST_TIME_LIMIT_MS: 40,
|
||||
},
|
||||
async () => {
|
||||
const js = Buffer.from(
|
||||
|
@ -2167,6 +2164,9 @@ describe.each([
|
|||
await config.api.row.save(table._id!, { text: "foo" })
|
||||
}
|
||||
|
||||
// Run this test 3 times to make sure that there's no cross-request
|
||||
// polution of the execution time tracking.
|
||||
for (let reqs = 0; reqs < 3; reqs++) {
|
||||
const { rows } = await config.api.row.search(table._id!)
|
||||
expect(rows).toHaveLength(10)
|
||||
|
||||
|
@ -2178,6 +2178,9 @@ describe.each([
|
|||
}
|
||||
}
|
||||
|
||||
// Given the execution times are not deterministic, we can't be sure
|
||||
// of the exact number of rows that were executed before the timeout
|
||||
// but it should absolutely be at least 1.
|
||||
expect(i).toBeGreaterThan(0)
|
||||
expect(i).toBeLessThan(5)
|
||||
|
||||
|
@ -2187,6 +2190,7 @@ describe.each([
|
|||
expect(row.formula).toBe("Request JS execution limit hit")
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue