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

Timeout handlers are always called #686

Closed
mucsi96 opened this issue Dec 4, 2016 · 2 comments
Closed

Timeout handlers are always called #686

mucsi96 opened this issue Dec 4, 2016 · 2 comments

Comments

@mucsi96
Copy link

mucsi96 commented Dec 4, 2016

I found an issue with current implementation of user_code_runner. If I add a console.log statement to the timeout handlers then I can see that the timeouts are not cleared if the step was successful. This is not visible because cucumber bin uses process.exit to force the exit. But if someone use Cucumber programatically and try to shutdown gracefully the node process will not exit until all timeouts finish. That was my case in /~https://github.com/mucsi96/nightwatch-cucumber when I tried to add cucumber 2 support. It was really hard to find why my node process is not exiting :)

timeout was called will be logged on every step.

const timeoutPromise = new Promise(function (resolve, reject) {
  clearTimeout = Time.setTimeout(function() {
    console.log('timeout was called');
    const timeoutMessage = 'function timed out after ' + timeoutInMilliseconds + ' milliseconds'
    reject(new Error(timeoutMessage))
  }, timeoutInMilliseconds)
})
racingPromises.push(timeoutPromise)

I wanted to submit a PR. But could not find a good way to test this :(
A solution whould be:

let timeoutId
const timeoutPromise = new Promise(function (resolve, reject) {
  timeoutId = Time.setTimeout(function() {
    const timeoutMessage = 'function timed out after ' + timeoutInMilliseconds + ' milliseconds'
    reject(new Error(timeoutMessage))
  }, timeoutInMilliseconds)
})
racingPromises.push(timeoutPromise)

let error, result
try {
  result = await Promise.race(racingPromises)
  timeoutId && Time.clearTimeout(timeoutId)
} catch (e) {
  timeoutId && Time.clearTimeout(timeoutId)
  if ((e instanceof Error)) {
    error = e
  } else if (e) {
    error = util.format(e)
  } else {
    error = 'Promise rejected without a reason'
  }
}
@mucsi96 mucsi96 changed the title Timeout handlers is always called Timeout handlers are always called Dec 4, 2016
@charlierudolph
Copy link
Member

2.0.0-rc.2 released with this fix

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants