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

feat: support parallel in before/afterAll hooks #2140

Closed
wants to merge 4 commits into from

Conversation

tim-yao
Copy link
Member

@tim-yao tim-yao commented Sep 15, 2022

🤔 What's changed?

⚡️ What's your motivation?

Fix #1153

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

@mattwynne
Copy link
Member

@davidjgoss I noticed that the errors from the workers' AfterAll hooks surfaced in quite an unexpected way. The Cucumber run itself shows 2 scenarios passed, but the overall run has exited with a non-zero code. If you scroll back up the output, you can see the errors reported from the Workers.

I recall we've discussed this elsewhere, that those worker errors should be printed in the main Cucumber console output. Should we maybe deal with that first?

@tim-yao tim-yao changed the title init the feature test file for parallel before/afterAll hooks feat: init the feature test file for parallel before/afterAll hooks Sep 17, 2022
@tim-yao tim-yao changed the title feat: init the feature test file for parallel before/afterAll hooks feat: support parallel in before/afterAll hooks Sep 17, 2022
@davidjgoss
Copy link
Contributor

davidjgoss commented Oct 3, 2022

@mattwynne

I recall we've discussed this elsewhere, that those worker errors should be printed in the main Cucumber console output. Should we maybe deal with that first?

I think that's a different and harder problem than the scope of this PR. It gets back to cucumber/messages#66 - we want to factor global hook failures into the formatter output so that it doesn't hide the failures, but we can't because formatters rely on the supply of messages, and global hooks are not represented in any messages. I'll comment on that issue and see if it goes anywhere.

@tim-yao sorry for the delay - I'll get you some feedback on this shortly.

@tim-yao
Copy link
Member Author

tim-yao commented Nov 18, 2022

Hi @davidjgoss any plan for this?

Copy link
Contributor

@davidjgoss davidjgoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A dropped a couple of comments inline which might be helpful for implementing this, plus here's a couple of links to relevant code:

If you need any pointers give me a nudge!

AfterAll({ parallelMode: HookParallelMode.WORKER_ONLY }, function() {
counter ++
console.log('worker: ', counter)
expect(counter).to.eql(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will work once we implement the changes - because the workers are in different Node.js processes, they won't be acting on the same counter variable, so I think it will always be 1 assuming the workers take one scenario each.

What might be worth pursuing instead is having each flavour of the hook console.log a string with the some of environment variables that Cucumber sets for the parallel runtime e.g CUCUMBER_WORKER_ID and then assert on that being in the output with a Then the output contains the text: step (see other features) - a bit messy but should work.

@@ -49,6 +49,10 @@ export {
} from './support_code_library_builder/world'
export { parallelCanAssignHelpers }

export const HookParallelMode = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a TS enum

@luke-hill
Copy link

I've put a comment on the original discussion thread @tim-yao - essentially suggesting we won't fix this.

If you want to continue and go ahead that's fine. But in essence this would be something JS-specific. It's not something I would evangelise porting to other languages, and the very nature of JS' async behaviour maybe lends itself to something that could be used here.

However in practicality (I won't copy my post from the issue), I just think this over-engineers a problem that could (and should), be solved in a different way. I'll let @davidjgoss maybe provide more JS-specific information as he's the subject expert in cucumberJS.

@tim-yao
Copy link
Member Author

tim-yao commented Jun 14, 2023

I've put a comment on the original discussion thread @tim-yao - essentially suggesting we won't fix this.

If you want to continue and go ahead that's fine. But in essence this would be something JS-specific. It's not something I would evangelise porting to other languages, and the very nature of JS' async behaviour maybe lends itself to something that could be used here.

However in practicality (I won't copy my post from the issue), I just think this over-engineers a problem that could (and should), be solved in a different way. I'll let @davidjgoss maybe provide more JS-specific information as he's the subject expert in cucumberJS.

That makes sense to me. I don't have the original issue anymore. It was from the HTML report plugin which requires after all hooks. It was broken in parallel. Since I move to use the default HTML formatter, I don't have the issue anymore. I will leave this PR to @davidjgoss. Feel free to close this or continue. Thanks.

@davidjgoss davidjgoss closed this Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BeforeAll hook is executed as many workers exist (in case of -parallel option)
4 participants