exitstatus = $?.exitstatus
if exitstatus.nil?
puts 'Something went wrong. Most likely, the process has been killed. Knapsack Pro has been terminated.'
Kernel.exit(1)
else
Kernel.exit(exitstatus)
end
[x] You added the changes to the UNRELEASED section of the CHANGELOG.md, including the needed bump (ie, patch, minor, major)
[x] More testing (including bin/knapsack_pro_all)
[x] 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.
Manual Tests
namespace :knapsack_pro do
namespace :queue do
task :rspec, [:rspec_args] do |_, args|
Kernel.exec("RAILS_ENV=test RACK_ENV=test RAILS_X=something #{$PROGRAM_NAME} 'knapsack_pro:queue:rspec_go[#{args[:rspec_args]}]'")
raise "err"
end
task :rspec_go, [:rspec_args] do |_, args|
puts ENV.filter { |k, v| k.include?("RAILS_") }
exit 10
end
end
end
namespace :knapsack_pro do
namespace :queue do
task :rspec, [:rspec_args] do |_, args|
Kernel.exec("RAILS_ENV=test RACK_ENV=test RAILS_X=something #{$PROGRAM_NAME} 'knapsack_pro:queue:rspec_go[#{args[:rspec_args]}]'")
raise "err"
end
task :rspec_go, [:rspec_args] do |_, args|
puts ENV.filter { |k, v| k.include?("RAILS_") }
raise StandardError
end
end
end
$ bin/knapsack_pro_queue_rspec 1 2 20240601-01
{"RAILS_X"=>"something", "RAILS_ENV"=>"test"}
rake aborted!
StandardError: StandardError (StandardError)
/Users/3v0k4/code/knapsack/knapsack_pro-ruby/lib/tasks/queue/rspec.rake:14:in `block (3 levels) in <top (required)>'
/Users/3v0k4/.rvm/gems/ruby-3.2.2/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
/Users/3v0k4/.rvm/gems/ruby-3.2.2/bin/ruby_executable_hooks:22:in `eval'
/Users/3v0k4/.rvm/gems/ruby-3.2.2/bin/ruby_executable_hooks:22:in `<main>'
Tasks: TOP => knapsack_pro:queue:rspec_go
(See full trace by running task with --trace)
Story
Ticket
#system
executes the passed command into a subshell. It pretty much executes fork, exec, and wait.#exec
replaces the current process avoiding a fork/wait.Also, using
exec
delegates the exit/error handling to the replacing process making the code introduced in https://github.com/KnapsackPro/knapsack_pro-ruby/commit/7862c5e6 unneeded:Also the following form seems to work:
See the
#spawn
docs for more on that.Reference:
Checklist reminder
UNRELEASED
section of theCHANGELOG.md
, including the needed bump (ie, patch, minor, major)bin/knapsack_pro_all
)lib/knapsack_pro/pure/queue/rspec_pure.rb
contains pure functions that are unit tested.lib/knapsack_pro/extensions/rspec_extension.rb
encapsulates calls to RSpec internals and is integration and e2e tested.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.Manual Tests