-
-
Notifications
You must be signed in to change notification settings - Fork 753
WIP: Removes bisect from SPEC_OPTS to prevent infinite recursion #2259
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,18 @@ module Bisect | |
# the given bisect server to capture the results. | ||
# @private | ||
class Runner | ||
attr_reader :original_cli_args | ||
attr_reader :original_cli_args, :original_spec_opts, :spec_opts | ||
|
||
def initialize(server, original_cli_args) | ||
@server = server | ||
@original_cli_args = original_cli_args.reject { |arg| arg.start_with?("--bisect") } | ||
@original_spec_opts = ENV['SPEC_OPTS'] | ||
if original_spec_opts =~ /--bisect/ | ||
bisect_arg = Shellwords.split(ENV["SPEC_OPTS"]).flatten.grep(/--bisect/).shift | ||
# mutate spec_opts | ||
ENV['SPEC_OPTS'] = ENV['SPEC_OPTS'].sub(bisect_arg, '') | ||
end | ||
@spec_opts = ENV['SPEC_OPTS'] | ||
end | ||
|
||
def run(locations) | ||
|
@@ -67,17 +74,22 @@ def run_locations(*capture_args) | |
end | ||
end | ||
|
||
# Consider just using Process.spawn since Open3 uses that. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you try using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, was my first attempt but a lot broke, so I revised strategy to look for how I could test it... In the end, decided to make a pr to let you see what I am thinking and trying, and if you have any ideas which is right place to test.... Thanks for looking Because I'm testing bisect, I can't run the results of a bisect on any failures :) B mobile phone
|
||
# `Open3.capture2e` does not work on JRuby: | ||
# https://github.com/jruby/jruby/issues/2766 | ||
if Open3.respond_to?(:capture2e) && !RSpec::Support::Ruby.jruby? | ||
def run_command(cmd) | ||
# consider passing in { 'SPEC_OPTS' => spec_opts } when not spec_opts.empty? | ||
# instead of mutating SPEC_OPTS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could do neither, have you got this working? |
||
Open3.capture2e(cmd).first | ||
end | ||
else # for 1.8.7 | ||
else # for 1.8.7 and JRuby | ||
# :nocov: | ||
def run_command(cmd) | ||
out = err = nil | ||
|
||
# consider passing in { 'SPEC_OPTS' => spec_opts } when not spec_opts.empty? | ||
# instead of mutating SPEC_OPTS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this can't be done now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't work first time and didn't think till right now that I can test effect of setting any env vars for arbitrary command, not just adding the hash and watching tests fail.... B mobile phone
|
||
Open3.popen3(cmd) do |_, stdout, stderr| | ||
# Reading the streams blocks until the process is complete | ||
out = stdout.read | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -291,6 +291,8 @@ def initialize_project_and_exit | |||||
def bisect_and_exit(argument) | ||||||
RSpec::Support.require_rspec_core "bisect/coordinator" | ||||||
|
||||||
# This might be the best spot to mutate ENV['SPEC_OPTS'] | ||||||
# if we do that. | ||||||
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't find an obvious spot in the ConfigurationOptions nor Configuration where this would go and then be available to the bisect runner, but if I check the env here at cli parsing and just pass that through the coordinator, that might be ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not obvious to me what's better about this spot then the spot you already have it. Can you explain? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm reading code correctly, I can handle the env vars here, or multiple times in each runner. B mobile phone
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only a single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surely a single instance per process... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A It's made here in the coordinator:
...and is then used repeatedly in the example minimizer to run specific example subsets:
|
||||||
success = Bisect::Coordinator.bisect_with( | ||||||
original_args, | ||||||
RSpec.configuration, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shift
here is very odd.shift
is likefirst
(a query) combined withdrop(1)
(a command) -- but you are only using it for the query part (since you keep no reference to the array being mutated), so I'd prefer to seefirst
be used.flatten
necessary? I don't see howShellwords.split
can result in an array that is not already flattened.grep(...).shift
(orgrep(...).first
) causes the entire list to be traversed, even if--bisect
is one of the first arguments. Instead, I'd usefind { ... }
.--bisect
in the spec opts multiple times: once in the conditional on the line above, and again on this line. That's wasted work.Putting all that together, I think this section can be simplified to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flatten came from from ConfigurationOptions iirc, where I couldn't figure out the right way to reuse that code.
Agree with your comments
B mobile phone