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

Optimize tests to run in parallel #1019

Merged
merged 10 commits into from
Aug 31, 2023
Merged

Optimize tests to run in parallel #1019

merged 10 commits into from
Aug 31, 2023

Conversation

inancgumus
Copy link
Member

@inancgumus inancgumus commented Aug 31, 2023

What?

  1. Makes unit and integration tests run in parallel.
  2. Makes some CI optimizations, considering that this is an optimization PR. Let me know if that part deserves another PR.

Why?

  1. The current tests take about 1 minute to run (locally), and there is no reason to run tests sequentially.
  2. This also lets us detect race conditions much faster and prevent unintended deadlocks in code.
  3. The E2E runner is hard to debug when running without the -q flag. With the flag, the result looks clearer to read and debug without the k6 banner and progress bar.

Here are the results after this change (On a 10-core machine):

Before: ~48s
After : ~24s

===Before===
ok      github.com/grafana/xk6-browser/browser  1.853s
ok      github.com/grafana/xk6-browser/common   1.669s
ok      github.com/grafana/xk6-browser/chromium 1.511s
ok      github.com/grafana/xk6-browser/tests    46.902s

===After===
ok      github.com/grafana/xk6-browser/browser  0.956s
ok      github.com/grafana/xk6-browser/common   0.689s
ok      github.com/grafana/xk6-browser/chromium 0.251s
ok      github.com/grafana/xk6-browser/tests    23.150s

On CI, it's the same because our runner runs on a 2-core. We can make this much faster if/when we run it on a more powerful runner.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Updates #1018

@inancgumus inancgumus self-assigned this Aug 31, 2023
@inancgumus inancgumus added tests dx developer experience optimization labels Aug 31, 2023
@inancgumus inancgumus changed the title Optimize to run tests in parallel Optimize tests to run in parallel Aug 31, 2023
@inancgumus inancgumus marked this pull request as ready for review August 31, 2023 07:22
@inancgumus inancgumus requested review from ankur22 and ka3de and removed request for ankur22 and ka3de August 31, 2023 07:22
@inancgumus inancgumus marked this pull request as draft August 31, 2023 07:28
@inancgumus inancgumus force-pushed the optimize/tests-to-parallel branch 2 times, most recently from d6a47da to fcfbc82 Compare August 31, 2023 08:19
@inancgumus inancgumus force-pushed the optimize/tests-to-parallel branch 2 times, most recently from 9ea8afe to cdccc4d Compare August 31, 2023 08:41
@inancgumus inancgumus marked this pull request as ready for review August 31, 2023 08:57
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on this @inancgumus ! 🙌
Just made a couple of comments. Also, I think there are a few tests missing to be executed in parallel or add a comment explaining why the can't not be run as such.

Unit tests:

  • TestBrowserContextOptionsPermissions
  • TestNewBrowserContext
  • TestConnection
  • TestConnectionClosureAbnormal
  • TestConnectionSendRecv
  • TestConnectionCreateSession
  • TestContextWithDoneChan
  • TestPageLocator

Integration tests:

  • TestLocatorPress

tests/element_handle_test.go Outdated Show resolved Hide resolved
tests/page_test.go Show resolved Hide resolved
@inancgumus
Copy link
Member Author

inancgumus commented Aug 31, 2023

Thank you for the review 🙇

TestBrowserContextOptionsPermissions, TestConnection, TestConnectionClosureAbnormal, TestConnectionSendRecv, TestConnectionCreateSession, TestContextWithDoneChan, TestPageLocator, TestLocatorPress.

Ah, I missed these ones; thanks! I'll make them parallel.

TestNewBrowserContext

I had sent this PR before our today's discussion in #1007. I was expecting #1007 to use globals, and it wouldn't make sense for this test to be parallel. After the discussion we had, we can make it parallel. WDYT?

ka3de
ka3de previously approved these changes Aug 31, 2023
Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

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

LGTM 👏

ankur22
ankur22 previously approved these changes Aug 31, 2023
Copy link
Collaborator

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

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

Nice! This is awesome! It takes much less time on my machine to run through all the tests.

tests/browser_test.go Show resolved Hide resolved
common/browser_context_test.go Show resolved Hide resolved
Before: ~45 sec
After : ~20 sec

This is measured on my 10-core machine. The results will drastically
change depending on the number of cores you have.
inancgumus and others added 7 commits August 31, 2023 16:10
This makes tests to run in parallel depending on a CI runner's number of
cores.
We can still get the output. Do we need the extra details like a
progress bar?
As the only current platform is Ubuntu.
Co-authored-by: ka3de <danijs12@hotmail.com>
After having a discussion, we decided to make this parallel. See the
related discussion here:
#1007 (comment)
After having a discussion, we decided to make this parallel. See the
related discussion here:
#1007 (comment)
@inancgumus inancgumus dismissed stale reviews from ankur22 and ka3de via c78e86c August 31, 2023 13:23
Copy link
Collaborator

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

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

Thanks for this 🙂

Copy link
Collaborator

@ka3de ka3de left a comment

Choose a reason for hiding this comment

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

LGTM.

@inancgumus inancgumus merged commit 4fd494f into main Aug 31, 2023
13 checks passed
@inancgumus inancgumus deleted the optimize/tests-to-parallel branch August 31, 2023 13:40
@inancgumus inancgumus added productivity Issues and PRs that improve our productivity and removed dx developer experience labels Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization productivity Issues and PRs that improve our productivity tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants