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

[Queue Mode][RSpec] Pass each batch of tests to the queue hooks: KnapsackPro::Hooks::Queue.before_subset_queue and KnapsackPro::Hooks::Queue.after_subset_queue #253

Merged
merged 18 commits into from
May 17, 2024

Conversation

ArturT
Copy link
Member

@ArturT ArturT commented May 16, 2024

Story

Link to the internal story

Related

Inspired by draft of PR:

Description

In RSpec when you use Queue Mode, the queue hooks KnapsackPro::Hooks::Queue.before_subset_queue and KnapsackPro::Hooks::Queue.after_subset_queue get a 3rd variable - the queue.

The queue variable stores an enumerable collection with each batch of tests fetched from the Queue API. The batch has:

  • a list of test file paths (KnapsackPro::Batch#test_file_paths returns an array like ['a_spec.rb', 'b_spec.rb'])
  • a status of the given set of tests in the batch (KnapsackPro::Batch#status returns :not_executed, :passed or :failed)

Example usage:

# spec_helper.rb

KnapsackPro::Hooks::Queue.before_subset_queue do |queue_id, subset_queue_id, queue|
  print "Tests from all batches fetched from the Queue API so far:  "
  puts queue.map(&:test_file_paths).inspect

  queue.each(&:test_file_paths) # you can use each as well

  print "Current batch tests: "
  puts queue.current_batch.test_file_paths.inspect

  print "Current batch status: "
  puts queue.current_batch.status # returns :not_executed in the `before_subset_queue` hook
end

KnapsackPro::Hooks::Queue.after_subset_queue do |queue_id, subset_queue_id, queue|
  print "Tests from all batches fetched from the Queue API so far: "
  puts queue.map(&:test_file_paths).inspect

  print "Current batch tests: "
  puts queue.current_batch.test_file_paths.inspect

  print "Current batch status: "
  puts queue.current_batch.status # returns :passed or :failed in the `after_subset_queue` hook
end

Checklist reminder

  • You follow the architecture outlined below for RSpec in Queue Mode, which is a work in progress (feel free to propose changes):
    • Pure: lib/knapsack_pro/pure/queue/rspec_pure.rb contains pure functions that are unit tested.
    • Extension: lib/knapsack_pro/extensions/rspec_extension.rb encapsulates calls to RSpec internals and is integration and e2e tested.
    • Runner: lib/knapsack_pro/runners/queue/rspec_runner.rb invokes the pure code and the extension to produce side effects, which are integration and e2e tested.

@ArturT ArturT requested a review from 3v0k4 May 16, 2024 20:32
Copy link
Contributor

@3v0k4 3v0k4 left a comment

Choose a reason for hiding this comment

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

Fantastic job!

If you end up applying all the comments related to the public API (batch.rb), consider this approved.

Happy to have a chat if you have any doubts about the CR.

lib/knapsack_pro/queue.rb Outdated Show resolved Hide resolved
lib/knapsack_pro/batch.rb Outdated Show resolved Hide resolved
spec/integration/runners/queue/rspec_runner_spec.rb Outdated Show resolved Hide resolved
lib/knapsack_pro/hooks/queue.rb Show resolved Hide resolved
spec/knapsack_pro/queue_spec.rb Outdated Show resolved Hide resolved
spec/knapsack_pro/queue_spec.rb Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Riccardo <riccardo.odone@gmail.com>
@ArturT ArturT changed the title [Queue Mode][RSpec] Add info about batch of tests in queue hooks: KnapsackPro::Hooks::Queue.before_subset_queue and KnapsackPro::Hooks::Queue.after_subset_queue [Queue Mode][RSpec] Pass each batch of tests to the queue hooks: KnapsackPro::Hooks::Queue.before_subset_queue and KnapsackPro::Hooks::Queue.after_subset_queue May 17, 2024
ArturT and others added 7 commits May 17, 2024 12:42
Co-authored-by: Riccardo <riccardo.odone@gmail.com>
Co-authored-by: Riccardo <riccardo.odone@gmail.com>
Co-authored-by: Riccardo <riccardo.odone@gmail.com>
Co-authored-by: Riccardo <riccardo.odone@gmail.com>
@ArturT
Copy link
Member Author

ArturT commented May 17, 2024

Fantastic job!

If you end up applying all the comments related to the public API (batch.rb), consider this approved.

Happy to have a chat if you have any doubts about the CR.

@3v0k4 I applied all the comments. I'll release the new gem version today.

@ArturT ArturT merged commit 43a38e9 into master May 17, 2024
45 checks passed
@ArturT ArturT deleted the rspec-track-queue-batches branch May 17, 2024 12:20
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.

2 participants