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

kie-issues#1114: Containerize Playwright end-to-end tests to resolve screenshot comparison issues caused by OS differences #2866

Merged
merged 42 commits into from
Feb 12, 2025

Conversation

ljmotta
Copy link
Contributor

@ljmotta ljmotta commented Jan 21, 2025

Closes apache/incubator-kie-issues#1114
Closes #2839

Description

This PR introduces containerized end-to-end (E2E) Playwright tests to ensure consistent and reliable test execution across environments. By default, after this PR, running the E2E tests locally and in the CI will use containers instead of running natively in the OS.

Tests were executed in the following environments:

  • macOS
    • arm64
    • Sonoma 14.6.1
    • Podman Desktop v1.15
    • Podman Engine 5.3.1
    • Docker CLI 27.2.1
  • macOS
    • amd64
    • Sonoma 14.5
    • Podman Desktop v1.16
    • Podman Engine 5.3.2
    • Docker CLI 274.0
  • Windows WSL
    • amd64
    • Ubuntu 22.04.3 LTS
    • Docker CE CLI 25.0.2
    • Docker CE Engine 25.0.2

This PR updates multiple screenshots, as the changes introduced allowed lowering the snapshot threshold from 10% to 0.1%!

Known Issues

  • Running the online-editor containerized test-e2e script on macOS requires starting the services in a separate terminal.
  • Performance: Tests may run slower on macOS arm64 due to architecture differences.
  • Flakiness: Retries are enabled because tests can occasionally fail without valid reasons when running in the restricted containerized environment.
  • Debugging tests is not currently supported but could be added in the future.
  • The Docker CLI is required to run the containerized tests.

Trying it out

  • Install the dependencies.
  • Build the @kie-tools/playwright-base image with the following command:
KIE_TOOLS_BUILD__buildContainerImages=true pnpm -F @kie-tools/playwright-base image:docker:build
  • In a package that contains Playwright e2e tests, run the following:
KIE_TOOLS_BUILD__runEndToEndTests=true pnpm test-e2e

This command will start the required services and run the tests inside the container.

Updating screenshots

To update screenshots, use the pnpm test-e2e:container:shell script to open a shell inside the container:

pnpm test-e2e:container:shell
# In the container shell, manually call the `test-e2e:run` passing the `-u` or `--update-snapshots` flag
pnpm test-e2e:run -u
# or
pnpm test-e2e:run --update-snapshots

To improve performance, you can filter which tests will run by adding the -g flag:

pnpm test-e2e:run -u -g "test name"

@ljmotta ljmotta added area:dependencies Pull requests that update a dependency file area:tests labels Jan 21, 2025
@ljmotta ljmotta self-assigned this Jan 21, 2025
@ljmotta ljmotta requested a review from tiagobento as a code owner January 21, 2025 22:08
@ljmotta ljmotta added the pr: wip PR is still under development label Jan 21, 2025
@jomarko
Copy link
Contributor

jomarko commented Jan 22, 2025

Thank you @ljmotta . Please, let us know this is ready for a verification. I will try on non-MAC environment.

@ljmotta
Copy link
Contributor Author

ljmotta commented Jan 23, 2025

@jomarko This PR can be tested for macOS and Linux. I still need to make some adjustments for native Windows (non WSL).

Copy link
Member

@thiagoelg thiagoelg left a comment

Choose a reason for hiding this comment

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

Awesome PR @ljmotta! This will make our e2e tests more stable and concise!

I've made some comments below about the package.json scripts; let me know what you think.

@ljmotta
Copy link
Contributor Author

ljmotta commented Jan 28, 2025

@tiagobento I've renamed KIE_TOOLS_BUILD__runContainerizedEndToEndTests to KIE_TOOLS_BUILD__containerizedEndToEndTests, and instead of using a new variable, I've made it a property of buildEnv.endToEndTests. I've also updated the scripts to follow the new behavior you described:

KIE_TOOLS_BUILD__runEndToEndTests=true ?
  KIE_TOOLS_BUILD__containerizedEndToEndTests=true ? 
    run_on_container : 
    run_on_host : 
  not_run

Currently, KIE Sandbox tests aren't working on macOS containers. I'm not sure why. I've tried debugging it, but I haven't found any obvious cause. The DMN and BPMN Editors are stuck in an infinite loading state and aren't fetching their respective envelopes. The shared worker is stuck in the git.init method, which calls the fs.exists method. From what I can see, the fs.exists method doesn't exist 😅.

@tiagobento
Copy link
Contributor

Did you try serving online-editor with something like http-server, for instance, instead of the Webpack Dev Server (pnpm start)?

@ljmotta
Copy link
Contributor Author

ljmotta commented Jan 29, 2025

@tiagobento http-server doesn't work too. I've tested with macOS in a amd64 machine, and the online-editor Google Chrome and Chormium tests passed with Docker and Podman.

@thiagoelg gave me the idea of removing the amd64 compatibility that Docker and Podman provide and running the container natively on the arm macOS. After removing the platform specification from the image build script and docker-compose file, the online-editor Chromium tests passed🎉 (Unfortunelly doesn't exist Google Chrome for Linux arm64). Everything points to a bug in the platform compatibility.

EDIT:
I see three ways we can proceed with this PR:

  1. Remove the platform flag, and disable all Google Chrome tests for Linux arm64.
  2. Keep the platform (since it works for the other packages) and disable Chromium and Google Chrome tests in the online-editor package.
  3. Make the arm64 macOS user generate an additional image for arm64 that will be used for the online-editor and without Google Chrome

@tiagobento
Copy link
Contributor

Thank you @ljmotta. From what I understand I believe the option benefiting the larger surface area would be option 2.

Please confirm if the following statement is correct:


If we go with option 2:

  • Developers on macOS arm64 trying to update online-editor screenshots won't be able to do so, and will need to find an alternative setup while we figure out what's the problem there.
  • Windows users will need to rely on WSL to update screenshots and we won't be pursuing finding the solution for non-WSL.

If this is accurate, then you have my blessing to go with it 😛

@ljmotta
Copy link
Contributor Author

ljmotta commented Jan 31, 2025

Yeah, that's correct. And just to be more clear. With option 2, the macOS arm64 users will not be able to run any online-editor Chromium and Google Chrome test inside the container.

@ljmotta ljmotta force-pushed the no-issue-playwright-containerization branch from 4a73e71 to d393657 Compare February 5, 2025 02:44
@ljmotta ljmotta force-pushed the no-issue-playwright-containerization branch 3 times, most recently from c412e61 to 0640d15 Compare February 6, 2025 22:20
@ljmotta ljmotta force-pushed the no-issue-playwright-containerization branch from 0a55a93 to 5539cbf Compare February 11, 2025 02:35
Copy link
Member

@thiagoelg thiagoelg left a comment

Choose a reason for hiding this comment

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

Awesome work @ljmotta! LGTM

@ljmotta ljmotta removed the pr: wip PR is still under development label Feb 11, 2025
@ljmotta
Copy link
Contributor Author

ljmotta commented Feb 11, 2025

I just double checked all screenshots. It's looking good. @tiagobento could you review the PR one more time?

@@ -61,6 +62,35 @@ const customConfig = defineConfig({
timeout: 240000,
},
],
// Override
projects: process.env.KIE_TOOLS_ONLINE_EDITOR__SKIP_PLAYWRIGHT_FOR_ARM64
Copy link
Contributor

Choose a reason for hiding this comment

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

Not using build-env here and directly accessing an env var. This is not aligned with the repository's convention...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This env var is only used for a workaround. I didn't add it to the build-env as it runs a bash script:

"test-e2e:container:up:darwin": KIE_TOOLS_ONLINE_EDITOR__SKIP_PLAYWRIGHT_FOR_ARM64=$( [[ $(uname -p) == \"arm\" ]] ...

I'm not sure how we could add this to the env.js file...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I could export the variable in the script, to use it in the playwright.config.ts... 😅

playwright:
platform: linux/amd64
container_name: kie-tools-playwright-containerization-scesim-editor
image: dev.local/${USER}/kie-tools-playwright-container-image:${PROJECT_VERSION}
Copy link
Contributor

Choose a reason for hiding this comment

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

This name is not parameterized, and the ${USER} component there seems unnecessary. WDYT about

dev.local/apache-kie-tools/playwright-e2e-tests-image?

@@ -61,6 +62,35 @@ const customConfig = defineConfig({
timeout: 240000,
},
],
// Override
projects: process.env.KIE_TOOLS_ONLINE_EDITOR__SKIP_PLAYWRIGHT_FOR_ARM64
Copy link
Contributor

Choose a reason for hiding this comment

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

Not using build-env to access an environment variable...

playwright:
platform: linux/amd64
container_name: kie-tools-playwright-containerization-online-editor
image: dev.local/${USER}/kie-tools-playwright-container-image:${PROJECT_VERSION}
Copy link
Contributor

@tiagobento tiagobento Feb 11, 2025

Choose a reason for hiding this comment

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

Images should have its tag version aligned with streamName, not with version.

Also the ${USER} component seems unnecessary..

WDYT about dev.local/apache-kie-tools/playwright-e2e-tests-image?

@tiagobento tiagobento merged commit 23da869 into apache:main Feb 12, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dependencies Pull requests that update a dependency file area:tests
Projects
None yet
4 participants