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

Parallel Execution - SupportCodeLibraryBuilder Not Loaded with Externalised Hook Information #2327

Open
tamil777selvan opened this issue Sep 22, 2023 · 5 comments
Labels
plugins-usecase A use case that could potentially by served by our nascent plugins concept

Comments

@tamil777selvan
Copy link

tamil777selvan commented Sep 22, 2023

πŸ‘“ What did you see?

Hooks that are loaded via supportCodeLibraryBuilder encounter an error when using the parallel option in the runCucumber API.

βœ… What did you expect to see?

Hooks loaded through supportCodeLibraryBuilder should be properly initialised and accessible, even when parallel mode is enabled.

πŸ“¦ Which tool/library version are you using?

Cucumber JS - 9.5.1

πŸ”¬ How could we reproduce it?

  1. Reset supportCodeLibraryBuilder.
  2. Import or require the files you want to use.
  3. Implement BeforeAll using supportCodeLibraryBuilder.methods.BeforeAll.
  4. Finalise supportCodeLibraryBuilder.

Once you've completed the above setup, you can invoke runCucumber with parallel: 0, and it should work as expected because it uses runTime.

However, if you set parallel: 1, you will encounter the following error because it uses the parallel coordinator.

TypeError: Cannot read properties of undefined (reading 'getInvocationParameters')
    at Object.run (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/src/runtime/step_runner.ts:34:43)
    at TestCaseRunner.invokeStep (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/src/runtime/test_case_runner.ts:137:29)
    at TestCaseRunner.runHook (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/src/runtime/test_case_runner.ts:273:23)
    at /Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/src/runtime/test_case_runner.ts:231:29
    at TestCaseRunner.aroundTestStep (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/src/runtime/test_case_runner.ts:170:34)
    at TestCaseRunner.runAttempt (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/src/runtime/test_case_runner.ts:218:18)
    at TestCaseRunner.run (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/src/runtime/test_case_runner.ts:188:40)
    at Worker.runTestCase (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/lib/runtime/parallel/worker.js:115:30)
    at Worker.receiveMessage (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/lib/runtime/parallel/worker.js:97:24)
    at process.<anonymous> (/Users/tamil/Desktop/workspace/cucumber-parallel/node_modules/@cucumber/cucumber/src/runtime/parallel/run_worker.ts:20:8)

πŸ“š Any additional context?

Code Snippet Used:

image


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

@davidjgoss
Copy link
Contributor

davidjgoss commented Sep 28, 2023

Hey @tamil777selvan, sorry for the late reply.

The support code loading for parallel is...a bit weird. We load it on the coordinator (from where we emit the messages about it) and then again on each worker (where the tests are actually going to be run). There's then a kind of sync process so they share the same ids in all places.

So if you jump in via the builder and add a hook on the coordinator only, there'll be a mismatch and thing will break in the way that you've seen.

I'm sure we can figure out a solution though. One of the things I've been looking at under the umbrella of Plugins is an extension point to prepend/append steps and hooks separate to the normal support code loading cycle. Also though, there might be other ways you can inject the behaviour you want besides a hook.

Can you say a bit more about the use case that's driving this?

@tamil777selvan
Copy link
Author

Hi @davidjgoss,

This scenario is particularly relevant when integrating WebdriverIO with Cucumber's parallel execution mechanism. When parallel execution is enabled, the WebdriverIO hooks invoked are not processed within the parallel coordinator, resulting in the observed issue.

@davidjgoss
Copy link
Contributor

the WebdriverIO hooks invoked

Could you say a bit more about what these hooks do? i.e. is it user-authored code, or more like wdio plumbing? If you were to put them in a file and add it to the require option, would that break in some way?

(I suspect there is some overlap with #2156 here.)

@tamil777selvan
Copy link
Author

@davidjgoss, these codes are provided by users and are integrated into Cucumber hooks through the support code library within the wdio-cucumber-framework. Even if we attempt to isolate this hook in a separate file and import it, it may not function as expected. The reason for this is that WebDriverIO hooks have their own names, and these names are internally mapped to corresponding Cucumber hooks.

For example, the beforeScenario WebDriverIO hook aligns with the before Cucumber hook.

This seems quite similar to the previous issue, as both cases involve the need to load custom hooks for parallel execution.

@davidjgoss
Copy link
Contributor

Thanks for the detail!

For this to work we have to find a way to have these user-authored hooks register on both the coordinator (parent) process and the worker processes.

I assume we don't have this problem for steps because users are calling the Cucumber Given, When, Then functions directly and we're loading that code via the require and/or import options? Would this be an option for the hooks too (e.g. use Before, BeforeAll, BeforeStep etc) or do the hooks get some special wdio-specific context/args passed to them?

@davidjgoss davidjgoss added the plugins-usecase A use case that could potentially by served by our nascent plugins concept label Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugins-usecase A use case that could potentially by served by our nascent plugins concept
Projects
None yet
Development

No branches or pull requests

2 participants