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

chore: increase step timeout to prevent flakiness #3518

Merged
merged 1 commit into from May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion test/e2e/step_definitions/core_steps.js
Expand Up @@ -31,7 +31,14 @@ When('I start a server in background', async function () {
})

When('I wait until server output contains:', async function (expectedOutput) {
await waitForCondition(() => this.backgroundProcess.stdout.includes(expectedOutput))
await waitForCondition(
() => this.backgroundProcess.stdout.includes(expectedOutput),
5000,
() => new Error(
'Expected server output to contain the above text within 5000ms, but got:\n\n' +
this.backgroundProcess.stdout
)
)
})

defineParameterType({
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/step_definitions/utils.js
Expand Up @@ -2,14 +2,18 @@ const { promisify } = require('util')

const sleep = promisify(setTimeout)

module.exports.waitForCondition = async (evaluateCondition, timeout = 1000) => {
module.exports.waitForCondition = async (evaluateCondition, timeout = 1000, customError = null) => {
let remainingTime = timeout
while (!evaluateCondition()) {
if (remainingTime > 0) {
await sleep(50)
remainingTime -= 50
} else {
throw new Error(`Condition not fulfilled, waited ${timeout}ms`)
if (customError != null) {
throw customError()
} else {
throw new Error(`Condition not fulfilled, waited ${timeout}ms`)
}
}
}
}