KnapsackPro / knapsack_pro-ruby

Knapsack Pro gem splits tests across parallel CI nodes and makes sure that tests run in optimal time
https://knapsackpro.com
MIT License
131 stars 27 forks source link

Refactor RSpec queue runner #226

Closed tubaxenor closed 6 months ago

tubaxenor commented 11 months ago

Currently rspec queue runner calls RSpec::Core::Runner#run multiple times for each batch and have to reset runner multiple times. This PR makes following changes:

ArturT commented 11 months ago

@tubaxenor Thank you for the PR. It looks great.

I added an internal ticket to our backlog to review this, test it and update specs.

I also enabled CircleCI builds for forked pull requests so we could run tests on this PR.

Is it fine if we would like to update something (code, specs, docs) in this PR? I see the option Maintainers are allowed to edit this pull request. is enabled.

Could you run knapsack_pro based on this fork on your CI for a week or two to ensure there are no edge cases or nothing unexpected happens?

Does it help to reduce memory pressure caused by RSpec on CI machines? I suspect memory pressure was bigger when using the RSpec split by test examples feature, how does it look now?

tubaxenor commented 11 months ago

Hi Artur, I am still running some experiment builds and will get back to you once there are some data comparison to shared.

You are more than welcome to make changes to this PR since I probably don't have much context of the spec setup and doc convention etc. I will still make some code changes mostly for the logging part to make the code cleaner and more readable.

ngan commented 11 months ago

Could you run knapsack_pro based on this fork on your CI for a week or two to ensure there are no edge cases or nothing unexpected happens?

We will be using this runner internally and report back.

Does it help to reduce memory pressure caused by RSpec on CI machines?

This is something that'll be hard to measure, but we'll try. Besides this, there are several other benefits:

As for the batch printouts, we can still let that happen between the green dots. We personally don't like it or use it, so we'd change the logging level to WARN to get rid of them. You could also log those batch information to files (which we do).

ArturT commented 11 months ago

I like the benefits you listed.

Keep us informed after you run this on your CI for some time. It would be nice if you could run this for your whole team. You could use the fork conditionally to have the option to quickly disable it for all feature branches in case you discover an unexpected issue.

For example, I use env var to decide if I want to use the knapsack_pro gem from the RubyGems or local copy: https://github.com/KnapsackPro/rails-app-with-knapsack_pro/blob/a5d9cbddb6f43ab0c33adf2399d7c680a0fa0e3a/Gemfile#L62

technicalpickles commented 11 months ago

Currently rspec queue runner calls RSpec::Core::Runner#run multiple times for each batch and have to reset runner multiple times.

I did find another benefit to doing this. If you have config.example_status_persistence_file_path set, you end up loading and dumping the status for all specs each time.

We ended up disabling this during CI. I could see it being a knapsack pro default if there is a good place to set it. (can create a separate issue for it).

ArturT commented 9 months ago

@ngan @tubaxenor Have you had a chance to measure the memory pressure reduction in your project case?

I'm curious if you see memory usage reduced by a few %, or maybe something more drastic like 10-50%, which would be a huge win. Thanks.

ngan commented 9 months ago

@ArturT we ended not measuring memory usage because it was too difficult to do with our test suite size...and we felt that the other benefits only was worth making this change.

But we've been using this code for 2 months now and it's been working well.

ArturT commented 9 months ago

@ngan Thanks for the info. We have this PR in our backlog to review it and verify its approach. We also need to sync it with our latest changes in the knapsack_pro gem 6.x around RSpec integration. We will keep you posted with further updates.

ArturT commented 8 months ago

@tubaxenor I tested your code to see if it can also help with the issue:

I noticed that RSpec ignores the --tag option provided to the Knapsack Pro command. The --format d or --format p works fine.

Example command: bundle exec rake "knapsack_pro:queue:rspec[--format d --tag mytag]"

Your code breaks the expected RSpec behavior because the --tag is ignored.

ArturT commented 8 months ago

I fixed the issue. The --tag option is respected by the RSpec now (commit - I'm doing refactor on a separate branch)

ArturT commented 6 months ago

We have released version 7.0.0 of the knapsack_pro gem. This version incorporates ideas from this pull request, among other enhancements.

Please find the migration steps at the following link: https://github.com/KnapsackPro/knapsack_pro-ruby/blob/master/CHANGELOG.md#700