summaryrefslogtreecommitdiff
path: root/test/lib/test/unit.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-03 12:52:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-03 12:52:09 +0000
commit0fe47fad55e15e890b7b45ffeaba47828760100d (patch)
tree01f4c1270f8fe55ddeb79a4ed3e78b582f27f286 /test/lib/test/unit.rb
parent953093e2a4c41370332906e8ee0a0bba2f867b20 (diff)
test/unit.rb: share job slots
* test/lib/test/unit.rb (Test::Unit::Parallel#_run_parallel): share job slots with GNU 'make'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/lib/test/unit.rb')
-rw-r--r--test/lib/test/unit.rb33
1 files changed, 32 insertions, 1 deletions
diff --git a/test/lib/test/unit.rb b/test/lib/test/unit.rb
index ad7620313d..2be96fe600 100644
--- a/test/lib/test/unit.rb
+++ b/test/lib/test/unit.rb
@@ -134,6 +134,23 @@ module Test
options
end
+ def non_options(files, options)
+ if !options[:parallel] and
+ /(?:\A|\s)--jobserver-auth=(\d+),(\d+)/ =~ ENV["MAKEFLAGS"]
+ begin
+ r = IO.for_fd($1.to_i(10), "rb", autoclose: false)
+ w = IO.for_fd($2.to_i(10), "wb", autoclose: false)
+ rescue
+ r.close if r
+ nil
+ else
+ @jobserver = [r, w]
+ options[:parallel] ||= 1
+ end
+ end
+ super
+ end
+
def status(*args)
result = super
raise @interrupt if @interrupt
@@ -173,9 +190,11 @@ module Test
class Worker
def self.launch(ruby,args=[])
+ opts = {}
+ @jobserver.each {|fd| opts[fd] = fd} if @jobserver
io = IO.popen([*ruby, "-W1",
"#{File.dirname(__FILE__)}/unit/parallel.rb",
- *args], "rb+")
+ *args], "rb+", opts)
new(io, io.pid, :waiting)
end
@@ -417,6 +436,7 @@ module Test
@workers = [] # Array of workers.
@workers_hash = {} # out-IO => worker
@ios = [] # Array of worker IOs
+ job_tokens = String.new(encoding: Encoding::ASCII_8BIT) if @jobserver
begin
[@tasks.size, @options[:parallel]].min.times {launch_worker}
@@ -426,6 +446,13 @@ module Test
(deal(io, type, result, rep).nil? and
!@workers.any? {|x| [:running, :prepare].include? x.status})
end
+ if job_tokens and !@tasks.empty? and !@workers.any? {|x| x.status == :ready}
+ t = @jobserver[0].read_nonblock([@tasks.size, @options[:parallel]].min, exception: false)
+ if String === t
+ job_tokens << t
+ t.size.times {launch_worker}
+ end
+ end
end
rescue Interrupt => ex
@interrupt = ex
@@ -439,6 +466,10 @@ module Test
end
quit_workers
+ if @jobserver
+ @jobserver[1] << job_tokens
+ job_tokens.clear
+ end
unless @interrupt || !@options[:retry] || @need_quit
parallel = @options[:parallel]