Skip to content
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

fix: properly close scheduling timer to avoid checkly test hanging #770

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Changes from 1 commit
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
18 changes: 13 additions & 5 deletions packages/cli/src/services/abstract-check-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export const DEFAULT_CHECK_RUN_TIMEOUT_SECONDS = 300

const DEFAULT_SCHEDULING_DELAY_EXCEEDED_MS = 20000

const SCHEDULING_DELAY_EXCEEDED_TIMEOUT_KEY = 'SCHEDULING_DELAY_EXCEEDED'

export default abstract class AbstractCheckRunner extends EventEmitter {
checks: Map<CheckRunId, { check: any, testResultId?: string }>
testSessionId?: string
Expand Down Expand Up @@ -203,9 +201,19 @@ export default abstract class AbstractCheckRunner extends EventEmitter {
}

private startSchedulingDelayTimeout () {
this.timeouts.set(SCHEDULING_DELAY_EXCEEDED_TIMEOUT_KEY, setTimeout(() =>
this.emit(Events.MAX_SCHEDULING_DELAY_EXCEEDED), DEFAULT_SCHEDULING_DELAY_EXCEEDED_MS,
))
let scheduledCheckCount = 0
const numChecks = this.checks.size
if (numChecks === 0) {
return
}
const schedulingDelayExceededTimeout = setTimeout(
() => this.emit(Events.MAX_SCHEDULING_DELAY_EXCEEDED),
DEFAULT_SCHEDULING_DELAY_EXCEEDED_MS,
)
clample marked this conversation as resolved.
Show resolved Hide resolved
this.on(Events.CHECK_INPROGRESS, () => {
scheduledCheckCount++
if (scheduledCheckCount === numChecks) clearTimeout(schedulingDelayExceededTimeout)
})
}

private disableTimeout (timeoutKey: string) {
Expand Down
Loading