Skip to content

Commit

Permalink
Remove DRb client runner
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Feb 15, 2021
1 parent 11928e0 commit 4a3a6f4
Show file tree
Hide file tree
Showing 20 changed files with 19 additions and 570 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def self.clear_examples
# convention is to use [RSpec.configure](RSpec#configure-class_method).
#
# @example
# RSpec.configuration.drb_port = 1234
# RSpec.configuration.profile_examples = 10
# @see RSpec.configure
# @see Core::Configuration
def self.configuration
Expand Down
8 changes: 3 additions & 5 deletions lib/rspec/core/bisect/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Bisect
# A DRb server that receives run results from a separate RSpec process
# started by the bisect process.
class Server
DRB_URI = "druby://localhost:8787"

def self.run
server = new
server.start
Expand All @@ -36,17 +38,13 @@ def start
DRb.install_acl ACL.new(%w[ deny all allow localhost allow 127.0.0.1 allow ::1 ])

# We pass `nil` as the first arg to allow it to pick a DRb port.
@drb = DRb.start_service(nil, self)
@drb = DRb.start_service(DRB_URI, self)
end

def stop
@drb.stop_service
end

def drb_port
@drb_port ||= Integer(@drb.uri[/\d+$/])
end

# Fetched via DRb by the BisectDRbFormatter to determine when to abort.
attr_accessor :expected_failures

Expand Down
9 changes: 2 additions & 7 deletions lib/rspec/core/bisect/shell_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module RSpec
module Core
module Bisect
# Provides an API to generate shell commands to run the suite for a
# set of locations, using the given bisect server to capture the results.
# set of locations, using the bisect server to capture the results.
# @private
class ShellCommand
attr_reader :original_cli_args
Expand All @@ -15,14 +15,13 @@ def initialize(original_cli_args)
@original_cli_args = original_cli_args.reject { |arg| arg.start_with?("--bisect") }
end

def command_for(locations, server)
def command_for(locations)
parts = []

parts << RUBY << load_path
parts << open3_safe_escape(RSpec::Core.path_to_executable)

parts << "--format" << "bisect-drb"
parts << "--drb-port" << server.drb_port

parts.concat(reusable_cli_options)
parts.concat(locations.map { |l| open3_safe_escape(l) })
Expand Down Expand Up @@ -85,10 +84,6 @@ def reusable_cli_options
@reusable_cli_options ||= begin
opts = original_cli_args_without_locations

if (port = parsed_original_cli_options[:drb_port])
opts -= %W[ --drb-port #{port} ]
end

parsed_original_cli_options.fetch(:formatters) { [] }.each do |(name, out)|
opts -= %W[ --format #{name} -f -f#{name} ]
opts -= %W[ --out #{out} -o -o#{out} ]
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/bisect/shell_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def original_results

def run_locations(*capture_args)
@server.capture_run_results(*capture_args) do
run_command @shell_command.command_for([], @server)
run_command @shell_command.command_for([])
end
end

Expand Down
14 changes: 2 additions & 12 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ module Core
#
# @example Standard settings
# RSpec.configure do |c|
# c.drb = true
# c.drb_port = 1234
# c.color_mode = :on
# c.default_path = 'behavior'
# c.filter_gems_from_backtrace "rack", "rake"
# end
#
# @example Hooks
Expand Down Expand Up @@ -124,16 +124,6 @@ def default_path=(path)
@default_path = path
end

# @macro add_setting
# Run examples over DRb (default: `false`). RSpec doesn't supply the DRb
# server, but you can use tools like spork.
# @return [Boolean]
add_setting :drb

# @macro add_setting
# The drb_port (default: nil).
add_setting :drb_port

# @macro add_setting
# Default: `$stderr`.
add_setting :error_stream
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/configuration_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def organize_options
end

UNFORCED_OPTIONS = Set.new([
:requires, :profile, :drb, :libs, :files_or_directories_to_run,
:requires, :profile, :libs, :files_or_directories_to_run,
:full_description, :full_backtrace, :tty
])

Expand Down
120 changes: 0 additions & 120 deletions lib/rspec/core/drb.rb

This file was deleted.

5 changes: 3 additions & 2 deletions lib/rspec/core/formatters/bisect_drb_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ module Formatters
# after each example.
# @private
class BisectDRbFormatter < BaseBisectFormatter
DRB_URI = "druby://localhost:8787"

def initialize(_output)
drb_uri = "druby://localhost:#{RSpec.configuration.drb_port}"
@bisect_server = DRbObject.new_with_uri(drb_uri)
@bisect_server = DRbObject.new_with_uri(DRB_URI)
RSpec.configuration.files_or_directories_to_run = @bisect_server.files_or_directories_to_run
super(Set.new(@bisect_server.expected_failures))
end
Expand Down
13 changes: 0 additions & 13 deletions lib/rspec/core/invocations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ def call(*_args)
end
end

# @private
class DRbWithFallback
def call(options, err, out)
require 'rspec/core/drb'
begin
return DRbRunner.new(options).run(err, out)
rescue DRb::DRbConnError
err.puts "No DRb server is running. Running in local process instead ..."
end
RSpec::Core::Runner.new(options).run(err, out)
end
end

# @private
class Bisect
def call(options, err, out)
Expand Down
9 changes: 0 additions & 9 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ def parser(options)
options[:error_exit_code] = code
end

parser.on('-X', '--[no-]drb', 'Run examples via DRb.') do |use_drb|
options[:drb] = use_drb
options[:runner] = RSpec::Core::Invocations::DRbWithFallback.new if use_drb
end

parser.on('--drb-port PORT', 'Port to connect to the DRb server.') do |o|
options[:drb_port] = o.to_i
end

parser.separator("\n **** Output ****\n\n")

parser.on('-f', '--format FORMATTER', 'Choose a formatter.',
Expand Down
1 change: 0 additions & 1 deletion spec/rspec/core/bisect/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ module RSpec::Core
end

def run_formatter_specs
RSpec.configuration.drb_port = server.drb_port
run_rspec_with_formatter("bisect-drb")
end

Expand Down
17 changes: 2 additions & 15 deletions spec/rspec/core/bisect/shell_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

module RSpec::Core
RSpec.describe Bisect::ShellCommand do
let(:server) { instance_double("RSpec::Core::Bisect::Server", :drb_port => 1234) }
let(:shell_command) { described_class.new(original_cli_args) }

describe "#command_for" do
def command_for(locations, options={})
load_path = options.fetch(:load_path) { [] }
orig_load_path = $LOAD_PATH.dup
$LOAD_PATH.replace(load_path)
shell_command.command_for(locations, server)
shell_command.command_for(locations)
ensure
$LOAD_PATH.replace(orig_load_path)
end
Expand All @@ -37,18 +36,6 @@ def command_for(locations, options={})
end
end

it "includes an option for the server's DRB port" do
cmd = command_for([])
expect(cmd).to include("--drb-port #{server.drb_port}")
end

it "ignores an existing --drb-port option (since we use the server's port instead)" do
original_cli_args << "--drb-port" << "9999"
cmd = command_for([])
expect(cmd).to include("--drb-port #{server.drb_port}").and exclude("9999")
expect(cmd.scan("--drb-port").count).to eq(1)
end

%w[ --bisect --bisect=verbose --bisect=blah ].each do |value|
it "ignores a `#{value}` option since that would infinitely recurse" do
original_cli_args << value
Expand Down Expand Up @@ -163,7 +150,7 @@ def repro_command_from(ids)

it 'includes original options that `command_for` excludes' do
original_cli_args << "--format" << "progress"
expect(shell_command.command_for(%w[ ./foo.rb[1:1] ], server)).to exclude("--format progress")
expect(shell_command.command_for(%w[ ./foo.rb[1:1] ])).to exclude("--format progress")
expect(repro_command_from(%w[ ./foo.rb[1:1] ])).to include("--format progress")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/core/bisect/shell_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module RSpec::Core
RSpec.describe Bisect::ShellRunner do
let(:server) { instance_double("RSpec::Core::Bisect::Server", :drb_port => 1234) }
let(:server) { instance_double("RSpec::Core::Bisect::Server") }
let(:shell_command) { Bisect::ShellCommand.new(original_cli_args) }
let(:runner) { described_class.new(server, shell_command) }

Expand Down
Loading

0 comments on commit 4a3a6f4

Please sign in to comment.