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

Cypress E2E Tests parallelization #3208

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open

Conversation

vicenteqa
Copy link

@vicenteqa vicenteqa commented Dec 17, 2024

Description

I am creating this PR to check in an isolated workflow changes that I may have to try to achieve Cypress parallelization.

As an starting point I copied the development made by @CDimonaco in his PR and took only the E2E part. I want to try this after some changes that I made in the E2E tests.

This PR implements Cypress Split plugin using 8 parallel threads.
To optimize test execution, I decoupled each test file, allowing it to run independently without relying on prior tests. This resolved issues where some tests required multiple executions of the "photofinish" main scenario, while others needed it to revert changes from previous tests. By executing "photofinish" once at the beginning of the test suite (either sequentially or in parallel in every CI thread) and removing unnecessary calls, overall test execution time has been reduced too.

PS:
This PR also adds ability to run each test file independently from other files to be run before, so now test files are decoupled.

I also added a small delay in start agent hearbeat function as I've noticed that it reduces flakiness in hosts_overview tests.

Fixes # (issue)

Did you add the right label?

Remember to add the right labels to this PR.

  • DONE

How was this tested?

Describe the tests that have been added/changed for this new behavior.

  • DONE

Did you update the documentation?

Remember to ask yourself if your PR requires changes to the following documentation:

Add a documentation PR or write that no changes are required for the documentation.

  • DONE

@vicenteqa vicenteqa added enhancement New feature or request test labels Dec 17, 2024
@vicenteqa vicenteqa marked this pull request as draft December 17, 2024 17:11
@vicenteqa vicenteqa changed the title POC for parallelization of Cypress Cypress E2E Tests parallelization Dec 20, 2024
@vicenteqa vicenteqa marked this pull request as ready for review December 20, 2024 13:15
Copy link
Member

@balanza balanza left a comment

Choose a reason for hiding this comment

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

Great job @vicenteqa! I'm very happy we came up with a solution that does not require an invasive refactor on code. To be honest, I wasn't so optimistic on that.

I left some comments on things I think we can improve. Besides that, I think we can merge.

Maybe we want to stage this PR for a while, to verify if tests are consistent after some changes to the codebase? We can rebase a couple of time and see.

Comment on lines 89 to 101
async function getPhotofinishBinaryAndGiveExecutablePermissions() {
const photofinishBinary = await runCommand(
'whereis photofinish | cut -d" " -f2'
);
await runCommand(`chmod +x ${photofinishBinary}`);
return photofinishBinary;
}

async function runPhotofinishMainScenario(photofinishBinary) {
return runCommand(
`cd ../.. && ${photofinishBinary} run --url "http://localhost:4000/api/collect" healthy-29-node-SAP-cluster`
);
}
Copy link
Member

Choose a reason for hiding this comment

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

question: ‏Why can't we use the loadScenario helper here?

Also, why the need to rewrite how we configure the photofinish command? See

`cd ${projectRoot} && ${photofinishBinary} run --url "http://${webAPIHost}:${webAPIPort}/api/collect" ${scenario}`

Copy link
Author

@vicenteqa vicenteqa Dec 20, 2024

Choose a reason for hiding this comment

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

because when this piece of code is executed, cy commands are still not available, cypress env parameters are not available either at that point of execution. Maybe we could use regular node env variables with process.env 🤔

Copy link
Member

Choose a reason for hiding this comment

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

process.env

Maybe it's better, we keep the same structure.

Also, if we don't use the loadScenario command anymore, should we remove it?

Copy link
Author

Choose a reason for hiding this comment

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

well, actually it is still used in some tests, specially to restore scenarios that previous test modified, and to load some other different scenarios.

Comment on lines 28 to 32
on('before:run', async () => {
const photofinishBinary =
await getPhotofinishBinaryAndGiveExecutablePermissions();
await runPhotofinishMainScenario(photofinishBinary);
});
Copy link
Member

Choose a reason for hiding this comment

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

question: ‏This means the scenario is loaded once per process, right?
So, given the target application is the same, the CI will be executed 8 times while on local execution just once.

Copy link
Author

Choose a reason for hiding this comment

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

that's it, once per process, so if you execute the whole test suite locally (sequential) this will be executed just once at the very beginning.

heartbeat_interval
);
heartbeatsIntervals.push(interval);
sleep(500).then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

issue: ‏Do you think we can better understand why it is needed, to remove it?
Sleeps on arbitrary time spans are often cause of flakiness, as they may depend on the running machine

Copy link
Author

Choose a reason for hiding this comment

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

I'm not a fan of arbitrary waits either and I know they should be avoided as a good practice, for the moment I don't have a conclusive answer tbh but I noticed that with a bit of delay the hosts_overview test flakiness is reduced a lot so I added it as a contingency measure, we can remove it if you want or even we can try the test flakiness tool designed by @gagandeepb then try with and without the arbitrary sleep and compare results.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have an alternative so I guess I must live with it 🤷‍♂️

@vicenteqa
Copy link
Author

Maybe we want to stage this PR for a while, to verify if tests are consistent after some changes to the codebase? We can rebase a couple of time and see.

I agree with this approach :)

@arbulu89 arbulu89 self-requested a review December 23, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request test
Development

Successfully merging this pull request may close these issues.

2 participants