Skip to content

[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
ArturT merged 18 commits intomasterfrom
rspec-track-queue-batches
May 17, 2024
Merged

[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
ArturT merged 18 commits intomasterfrom
rspec-track-queue-batches

Conversation

@ArturT
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread lib/knapsack_pro/queue.rb Outdated
Comment thread lib/knapsack_pro/batch.rb
Comment thread spec/integration/runners/queue/rspec_runner_spec.rb Outdated
Comment thread lib/knapsack_pro/hooks/queue.rb
Comment thread spec/knapsack_pro/queue_spec.rb Outdated
Comment thread spec/knapsack_pro/queue_spec.rb Outdated
Comment thread CHANGELOG.md Outdated
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
Copy Markdown
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.

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