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

chore: integration: add tests for browser scripts and metrics #81

Merged
merged 2 commits into from
Mar 11, 2025

Conversation

nadiamoe
Copy link
Member

@nadiamoe nadiamoe commented Mar 5, 2025

This adds a browser script to the integration test suite, which for now only tests for presence of a couple trivial metrics.

Now, of course that makes the thing look easier than it is: To run browser tests we need a browser, and to run browser tests on CI/CD we need to either be reckless and install chromium on the GitHub runners, or to use Crocochrome. As I think we all like the second alternative better, this PR introduces Crocochrome.

Even though the croc simplifies things a lot, there are a couple things that tests need to take care of:

  1. Start and stop the crocochrome container
  2. Create and destroy sessions using the crocochrome API.

In https://github.com/grafana/sm-k6-runner/pull/201/, which did a very similar thing for the runner, I chose to use testcontainers for crocochrome, mainly because the testcontainers dep was already there. Here, I'm trying to see how crazy it would be to not use testcontainers, and instead YOLO-run docker commands.

Looking forward to reviewer's thoughts on how that looks: If someone strongly opposes to trying this as an experiment, I can fall back to testcontainers and its gazillion dependencies. If there's no strong opposition, I suggest we give this a try: Falling back to testcontainers if this is flaky should be close to no effort.

As for the crocochrome API, a couple of quick & dirty functions are implemented to use it.

@nadiamoe nadiamoe changed the title chore: integration: extract script run to a helper function chore: integration: add tests for browser scripts and metrics Mar 5, 2025
@nadiamoe nadiamoe requested review from d0ugal, a team and The-9880 and removed request for a team March 5, 2025 17:28
@nadiamoe nadiamoe marked this pull request as ready for review March 5, 2025 17:28
@nadiamoe nadiamoe requested a review from a team as a code owner March 5, 2025 17:28
Base automatically changed from integration-metrics-helper to main March 6, 2025 13:43
@nadiamoe nadiamoe force-pushed the integration-browser-2 branch from 1b1763c to 3830589 Compare March 6, 2025 14:22

try {
// e-commerce site as a torture test for metric generation.
await page.goto('https://www.amazon.com');
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than depending on an external source, we could use custom metrics in k6 but with the builtin names. This would likely increase the stability but it a little tedious. An idea for the future maybe!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I think producing a torture-test locally would be a good next step!
Ideally we should return some actual HTML with loads of (mocked) images and scripts.

@nadiamoe nadiamoe merged commit 7d2f8b6 into main Mar 11, 2025
8 checks passed
@nadiamoe nadiamoe deleted the integration-browser-2 branch March 11, 2025 13:32
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.

2 participants