Skip to content

Commit

Permalink
Use Testing::Parallelization in Action Packs's test
Browse files Browse the repository at this point in the history
Parallel execution of `ForkingExecutor` is the same approach as
`Testing::Parallelization`. So do not need to have own code inside
Action Pack. Let's use an already existing feature.
  • Loading branch information
y-yagi committed Nov 28, 2018
1 parent 8687a03 commit 4b5c4ca
Showing 1 changed file with 1 addition and 77 deletions.
78 changes: 1 addition & 77 deletions actionpack/test/abstract_unit.rb
Expand Up @@ -13,13 +13,6 @@
Encoding.default_external = Encoding::UTF_8
end

require "drb"
begin
require "drb/unix"
rescue LoadError
puts "'drb/unix' is not available"
end

if ENV["TRAVIS"]
PROCESS_COUNT = 0
else
Expand Down Expand Up @@ -80,7 +73,7 @@ def before_setup
module ActiveSupport
class TestCase
if RUBY_ENGINE == "ruby" && PROCESS_COUNT > 0
parallelize_me!
parallelize(workers: PROCESS_COUNT)
end
end
end
Expand Down Expand Up @@ -359,75 +352,6 @@ class ImagesController < ResourcesController; end

require "active_support/testing/method_call_assertions"

class ForkingExecutor
class Server
include DRb::DRbUndumped

def initialize
@queue = Queue.new
end

def record(reporter, result)
reporter.record result
end

def <<(o)
o[2] = DRbObject.new(o[2]) if o
@queue << o
end
def pop; @queue.pop; end
end

def initialize(size)
@size = size
@queue = Server.new
@pool = nil
@url = DRb.start_service("drbunix:", @queue).uri
end

def <<(work); @queue << work; end

def shutdown
pool = @size.times.map {
fork {
DRb.stop_service
queue = DRbObject.new_with_uri @url
while job = queue.pop
klass = job[0]
method = job[1]
reporter = job[2]
result = Minitest.run_one_method klass, method
if result.error?
translate_exceptions result
end
queue.record reporter, result
end
}
}
@size.times { @queue << nil }
pool.each { |pid| Process.waitpid pid }
end

private
def translate_exceptions(result)
result.failures.map! { |e|
begin
Marshal.dump e
e
rescue TypeError
ex = Exception.new e.message
ex.set_backtrace e.backtrace
Minitest::UnexpectedError.new ex
end
}
end
end

if RUBY_ENGINE == "ruby" && PROCESS_COUNT > 0
# Use N processes (N defaults to 4)
Minitest.parallel_executor = ForkingExecutor.new(PROCESS_COUNT)
end

class ActiveSupport::TestCase
include ActiveSupport::Testing::MethodCallAssertions

Expand Down

0 comments on commit 4b5c4ca

Please sign in to comment.