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: provide worker id to envelope message #2085

Merged
merged 14 commits into from
Nov 14, 2022

Conversation

epszaw
Copy link
Member

@epszaw epszaw commented Jul 4, 2022

🤔 What's changed?

Add optional workerId parameter to some envelopes to access it inside the custom formaters

⚡️ What's your motivation?

allure-cucumberjs needs to have access to thread or worker id for better reports.

🏷️ What kind of change is this?

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

♻️ Anything particular you want feedback on?

Recently I opened another PR to generic repo cucumber/common#2033, but this repo is the best place to implement the functionality. Due we can't extend Envelope type, I decided to leave it as is, but we can create extended one locally and use it inside the related handlers. Like:

import { Envelope } from '@cucumber/messages'

type Envelope = Envelope & { workerId?: string }

📋 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.

@coveralls
Copy link

coveralls commented Jul 4, 2022

Coverage Status

Coverage increased (+0.001%) to 98.255% when pulling 6cc0638 on epszaw:feat/provide-worker-id-to-envelope into 1d5d345 on cucumber:main.

@aurelien-reeves
Copy link
Contributor

@davidjgoss @charlierudolph this being very technical, and David I know you already have some future plans for cucumber-js, so I let you take a look on that one? If this is actually an issue let me know, I'll do my best to have a proper look on it.

@davidjgoss
Copy link
Contributor

Doing this on every envelope seems a little excessive to me, and I'd rather not start going our own way with the schema.

From the use case you've described, I think the level we need this at would be testCaseStarted - so you can know which worker each test case ran on and can partition data on that basis? I feel like that's a targeted and reasonable enough change to go on the canonical schema as an optional field.

WDYT @aurelien-reeves @charlierudolph @aslakhellesoy?

@baev
Copy link

baev commented Jul 4, 2022

The more generic solution would be to supply process.env in some sort of envelope that notifies about run start (and triggered once per worker)

@aurelien-reeves
Copy link
Contributor

I am still not convinced that should be part of the schemas are this is only related to cucumber-js.

And I still do not understand why this could not be part of the formatter itself

@baev
Copy link

baev commented Jul 4, 2022

And I still do not understand why this could not be part of the formatter itself

BTW what exactly do you mean by saying that?

@aurelien-reeves
Copy link
Contributor

aurelien-reeves commented Jul 4, 2022

BTW what exactly do you mean by saying that?

I mean that with something as simple as the following inside a formatter, I have been able to retrieve the workerId (with parallel set to 3):

    options.eventBroadcaster.on('envelope', (envelope: messages.Envelope) => {
      if (doesHaveValue(envelope.testCaseStarted)) {
        console.log(`worker id: '${process.env.CUCUMBER_WORKER_ID}'`)
      }
    }

Well, @david with such a simple experiment I had some weird results actually:

worker id: 'undefined'
worker id: 'undefined'
worker id: '2'
worker id: '0'
worker id: '0'
worker id: 'undefined'
worker id: 'undefined'
worker id: 'undefined'
worker id: '2'
worker id: '2'
worker id: 'undefined'
worker id: '0'
worker id: '0'
worker id: 'undefined'
worker id: 'undefined'
worker id: '0'
worker id: '0'
worker id: '1'
worker id: '1'
worker id: 'undefined'
worker id: '2'
worker id: '2'
worker id: 'undefined'
worker id: 'undefined'
worker id: '0'
worker id: '0'
worker id: '2'
worker id: '2'
worker id: 'undefined'
worker id: 'undefined'
worker id: 'undefined'
worker id: 'undefined'
worker id: '1'
worker id: '1'
worker id: 'undefined'
worker id: '1'
worker id: '1'
worker id: 'undefined'
worker id: '1'
worker id: '1'
worker id: 'undefined'
worker id: 'undefined'
worker id: '1'
worker id: '1'
worker id: 'undefined'
worker id: 'undefined'
worker id: '1'
worker id: '1'
worker id: 'undefined'
worker id: 'undefined'
worker id: 'undefined'
worker id: '2'
worker id: '2'
worker id: 'undefined'
worker id: 'undefined'
worker id: '2'
worker id: '2'
worker id: 'undefined'
worker id: 'undefined'
worker id: '1'
worker id: 'undefined'
worker id: 'undefined'
worker id: '2'
worker id: 'undefined'
worker id: '1'
worker id: 'undefined'
worker id: '1'
worker id: 'undefined'
worker id: '1'
worker id: 'undefined'
worker id: '1'
worker id: 'undefined'
worker id: '1'
worker id: 'undefined'
worker id: '1'
worker id: '0'
36 scenarios (36 passed)

There are two things to notice here:

  • there are far more log entries than there are scenarios
  • the 'undefined' worker id

Is this kinda expected?

@baev
Copy link

baev commented Jul 4, 2022

as far as I know, formatter is executed in parent process, and have no access worker id which is only passed to child process. That's the reason we raised this issue in the first place

@davidjgoss
Copy link
Contributor

@baev yes that's right, the coordinator does the formatters.

@aurelien-reeves how did you do that experiment? Was it in a new clean project using cucumber?

@aurelien-reeves
Copy link
Contributor

as far as I know, formatter is executed in parent process, and have no access worker id which is only passed to child process. That's the reason we raised this issue in the first place

@baev yes that's right, the coordinator does the formatters.

Oops, sorry for the confusion. My mistake 😓

@aurelien-reeves how did you do that experiment? Was it in a new clean project using cucumber?

Directly on main in cucumber-js codebase. I have just patched the "summary_formatter" with the code I have copied earlier

@davidjgoss
Copy link
Contributor

Directly on main in cucumber-js codebase. I have just patched the "summary_formatter" with the code I have copied earlier

Okay that's going to get confusing because you have cucumber running within cucumber. If you run with --parallel 3, the values you're seeing are probably where the cucumber process under test is running within a worker.

@aurelien-reeves
Copy link
Contributor

Directly on main in cucumber-js codebase. I have just patched the "summary_formatter" with the code I have copied earlier

Okay that's going to get confusing because you have cucumber running within cucumber. If you run with --parallel 3, the values you're seeing are probably where the cucumber process under test is running within a worker.

Ok, I see
Sorry again for the confusion

@epszaw
Copy link
Member Author

epszaw commented Jul 11, 2022

Any news here, guys?

@davidjgoss
Copy link
Contributor

Sorry for the late reply @lamartire.

I talked this over with some of the wider Cucumber team today, and there's broad agreement that the concept of a test case being run in a worker process is worth being in the message schema. I think this would be better than diverging just in cucumber-js, because it can benefit other implementations too (the Ruby one for example).

Before I do anything though, I just want to make sure I understand the need from Allure so that we can make a reasonably small and targeted change initially. From what I've seen, it seems like a workerId (or whatever we call it) field on the testCaseStarted message should be sufficient for a message consumer to be able to segment test execution data based on the worker. Does that sound right to you?

cc @mattwynne @mpkorstanje

@epszaw
Copy link
Member Author

epszaw commented Jul 15, 2022

It sounds correct. Does it, @baev?

@baev
Copy link

baev commented Jul 15, 2022

Sounds good to me

@davidjgoss
Copy link
Contributor

davidjgoss commented Aug 25, 2022

Just an update, I raised cucumber/messages#34 today to get this into the message schema (per my earlier comment). Once that is in, I should be able to get a version of cucumber-js out pretty fast with the relevant changes.

@epszaw
Copy link
Member Author

epszaw commented Oct 18, 2022

So, as I can see the PR has been merged many time ago :)
What do you think, @davidjgoss, is it necessary to provide workerId property to any envelope?
Of course we can assemble all the things based on test case information (I guess), but from my point – having the property everywhere is very useful thing.

@epszaw epszaw force-pushed the feat/provide-worker-id-to-envelope branch 2 times, most recently from db3211c to ab7926a Compare October 21, 2022 09:25
@epszaw
Copy link
Member Author

epszaw commented Oct 21, 2022

So, I updated the PR up to the new messages API. Even if you won't decide to provide workerId everywhere – it's ready to merge with the current solution :)

@davidjgoss
Copy link
Contributor

@epszaw thanks for adapting this PR! It should be mergeable once I get the messages change released which I’m working on now.

@epszaw epszaw force-pushed the feat/provide-worker-id-to-envelope branch from ab7926a to 2218976 Compare November 2, 2022 14:29
@epszaw
Copy link
Member Author

epszaw commented Nov 2, 2022

@davidjgoss done 👍

@davidjgoss davidjgoss merged commit 3bd70c8 into cucumber:main Nov 14, 2022
@aslakhellesoy
Copy link
Contributor

Hi @epszaw,

Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾

In return for this generous offer we hope you will:

  • ✅ Continue to use branches and pull requests. When someone on the core team approves a pull request (yours or someone else's), you're welcome to merge it yourself.
  • 💚 Commit to setting a good example by following and upholding our code of conduct in your interactions with other collaborators and users.
  • 💬 Join the community Slack channel to meet the rest of the team and make yourself at home.
  • ℹ️ Don't feel obliged to help, just do what you can if you have the time and the energy.
  • 🙋 Ask if you need anything. We're looking for feedback about how to make the project more welcoming, so please tell us!

On behalf of the Cucumber core team,
Aslak Hellesøy
Creator of Cucumber

@epszaw
Copy link
Member Author

epszaw commented Nov 14, 2022

Yay! 🙌

@davidjgoss
Copy link
Contributor

This was released in 8.8.0 https://github.com/cucumber/cucumber-js/releases/tag/v8.8.0

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.

None yet

6 participants