mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test/unit.rb: job tokens
* test/lib/test/unit.rb (_run_parallel): deal with job tokens for each workers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
36037442be
commit
1f23dd016b
1 changed files with 15 additions and 9 deletions
|
@ -253,7 +253,6 @@ module Test
|
||||||
return if @io.closed?
|
return if @io.closed?
|
||||||
@quit_called = true
|
@quit_called = true
|
||||||
@io.puts "quit"
|
@io.puts "quit"
|
||||||
@io.close
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def kill
|
def kill
|
||||||
|
@ -296,6 +295,10 @@ module Test
|
||||||
def after_worker_down(worker, e=nil, c=false)
|
def after_worker_down(worker, e=nil, c=false)
|
||||||
return unless @options[:parallel]
|
return unless @options[:parallel]
|
||||||
return if @interrupt
|
return if @interrupt
|
||||||
|
if @jobserver
|
||||||
|
@jobserver[1] << @job_tokens
|
||||||
|
@job_tokens.clear
|
||||||
|
end
|
||||||
warn e if e
|
warn e if e
|
||||||
real_file = worker.real_file and warn "running file: #{real_file}"
|
real_file = worker.real_file and warn "running file: #{real_file}"
|
||||||
@need_quit = true
|
@need_quit = true
|
||||||
|
@ -311,6 +314,10 @@ module Test
|
||||||
def after_worker_quit(worker)
|
def after_worker_quit(worker)
|
||||||
return unless @options[:parallel]
|
return unless @options[:parallel]
|
||||||
return if @interrupt
|
return if @interrupt
|
||||||
|
worker.close
|
||||||
|
if @jobserver and !@job_tokens.empty?
|
||||||
|
@jobserver[1] << @job_tokens.slice!(0)
|
||||||
|
end
|
||||||
@workers.delete(worker)
|
@workers.delete(worker)
|
||||||
@dead_workers << worker
|
@dead_workers << worker
|
||||||
@ios = @workers.map(&:io)
|
@ios = @workers.map(&:io)
|
||||||
|
@ -377,7 +384,10 @@ module Test
|
||||||
bang = $1
|
bang = $1
|
||||||
worker.status = :ready
|
worker.status = :ready
|
||||||
|
|
||||||
return nil unless task = @tasks.shift
|
unless task = @tasks.shift
|
||||||
|
worker.quit
|
||||||
|
return nil
|
||||||
|
end
|
||||||
if @options[:separate] and not bang
|
if @options[:separate] and not bang
|
||||||
worker.quit
|
worker.quit
|
||||||
worker = add_worker
|
worker = add_worker
|
||||||
|
@ -437,7 +447,7 @@ module Test
|
||||||
@workers = [] # Array of workers.
|
@workers = [] # Array of workers.
|
||||||
@workers_hash = {} # out-IO => worker
|
@workers_hash = {} # out-IO => worker
|
||||||
@ios = [] # Array of worker IOs
|
@ios = [] # Array of worker IOs
|
||||||
job_tokens = String.new(encoding: Encoding::ASCII_8BIT) if @jobserver
|
@job_tokens = String.new(encoding: Encoding::ASCII_8BIT) if @jobserver
|
||||||
begin
|
begin
|
||||||
[@tasks.size, @options[:parallel]].min.times {launch_worker}
|
[@tasks.size, @options[:parallel]].min.times {launch_worker}
|
||||||
|
|
||||||
|
@ -447,10 +457,10 @@ module Test
|
||||||
(deal(io, type, result, rep).nil? and
|
(deal(io, type, result, rep).nil? and
|
||||||
!@workers.any? {|x| [:running, :prepare].include? x.status})
|
!@workers.any? {|x| [:running, :prepare].include? x.status})
|
||||||
end
|
end
|
||||||
if job_tokens and !@tasks.empty? and !@workers.any? {|x| x.status == :ready}
|
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)
|
t = @jobserver[0].read_nonblock([@tasks.size, @options[:parallel]].min, exception: false)
|
||||||
if String === t
|
if String === t
|
||||||
job_tokens << t
|
@job_tokens << t
|
||||||
t.size.times {launch_worker}
|
t.size.times {launch_worker}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -467,10 +477,6 @@ module Test
|
||||||
end
|
end
|
||||||
|
|
||||||
quit_workers
|
quit_workers
|
||||||
if @jobserver
|
|
||||||
@jobserver[1] << job_tokens
|
|
||||||
job_tokens.clear
|
|
||||||
end
|
|
||||||
|
|
||||||
unless @interrupt || !@options[:retry] || @need_quit
|
unless @interrupt || !@options[:retry] || @need_quit
|
||||||
parallel = @options[:parallel]
|
parallel = @options[:parallel]
|
||||||
|
|
Loading…
Reference in a new issue