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

Add before_subset_queue hook in queue mode #183

Merged
merged 3 commits into from
Dec 5, 2022

Conversation

tubaxenor
Copy link
Contributor

Currently there is only after_subset_queue hook and only works when subset finished. Adding a before subset hook to provide an ability to access to the subset queue to preserve some information beforehand which might be loss while CI node terminated in the middle of processing.

@ArturT
Copy link
Member

ArturT commented Dec 2, 2022

Hi @tubaxenor

Please share more context why this is needed in your case.

Do you use RSpec or another test runner?

In the case of RSpec, you can run before(:suite) hook. It's executed before each subset queue (batch of tests fetched from Queue API).

Have you tried it? If so, why it's not good enough?
It would help me better understand your use case. Thank you.

@ngan
Copy link

ngan commented Dec 5, 2022

Hey @ArturT, you’re right, before(:suite) would do same thing. However, it feels really weird use the after subset hook (a Knapsack pro concept) for some things and before(:suite) (an RSpec concept) for others. It also seems natural to offer a before subset hook if you offer an after subset hook, no?

:after_subset_queue_store,
:after_queue_store

def reset_before_queue
@before_queue_store = nil
end

def reset_before_subset_queue
@before_subset_queue_store = nil
Copy link
Member

Choose a reason for hiding this comment

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

I noticed specs where flaky (randomly failing) and I could not figure out why. It turned out there was a wrong name for this instance variable. I've fixed it and now specs are passing.

@ArturT
Copy link
Member

ArturT commented Dec 5, 2022

code example

You can use the before_subset_queue hook to preview a list of test files fetched from the Queue API in a given batch of tests.

KnapsackPro::Hooks::Queue.before_subset_queue do |queue_id|
  # list of test files fetched from the Queue API for a given batch/subset
  # tests are not executed yet so the time_execution is 0 seconds
  puts KnapsackPro.tracker.to_a
end

I've released the knapsack_pro gem 3.5.0 version.

@ArturT
Copy link
Member

ArturT commented Dec 5, 2022

@tubaxenor @ngan Thank you for the contribution. 🎉

@tubaxenor tubaxenor deleted the feature/add-before-subset branch December 7, 2022 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants