Files
overleaf-cep/server-ce/test/helpers/compile.ts
Jakob Ackermann 245473c1ac [server-pro] tests: backport changes from SaaS E2E tests (#23921)
* [server-pro] tests: add helper for gitURL

* [server-pro] tests: avoid hard-coding URL scheme/origin

* [server-pro] tests: fix typo in query selector

* [server-pro] tests: fix spelling of GitHub

* [server-pro] tests: double down on matching email in body

* [server-pro] tests: speed up session resumption

* [server-pro] tests: use a single project in editor spec

* [server-pro] drop check on started recompile

The labels changed between versions and making it configurable is too
verbose.

GitOrigin-RevId: d1ace3b534f28c65b8e20c808bac12268f26fa4d
2025-02-27 09:06:03 +00:00

41 lines
1.3 KiB
TypeScript

/**
* Helper function for throttling clicks on the recompile button to avoid hitting server side rate limits.
* The naive approach is waiting a fixed a mount of time (3s) just before clicking the button.
* This helper takes into account that other UI interactions take time. We can deduce that latency from the fixed delay (3s minus other latency). This can bring down the effective waiting time to 0s.
*/
export function throttledRecompile() {
const { queueReset, recompile } = prepareWaitForNextCompileSlot()
queueReset()
return recompile
}
export function prepareWaitForNextCompileSlot() {
let lastCompile = 0
function queueReset() {
cy.then(() => {
lastCompile = Date.now()
})
}
function waitForCompileRateLimitCoolOff(triggerCompile: () => void) {
cy.then(() => {
cy.log('Wait for recompile rate-limit to cool off')
const msSinceLastCompile = Date.now() - lastCompile
cy.wait(Math.max(0, 1_000 - msSinceLastCompile))
queueReset()
triggerCompile()
cy.log('Wait for compile to finish')
cy.findByText('Recompile')
})
}
function recompile() {
waitForCompileRateLimitCoolOff(() => {
cy.findByText('Recompile').click()
})
}
return {
queueReset,
waitForCompileRateLimitCoolOff,
recompile,
}
}