autosort files by historical time.
This commit is contained in:
parent
4cccecc92f
commit
559e236d86
|
@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Nick Gauthier"]
|
s.authors = ["Nick Gauthier"]
|
||||||
s.date = %q{2010-02-17}
|
s.date = %q{2010-02-18}
|
||||||
s.description = %q{Spread your tests over multiple machines to test your code faster.}
|
s.description = %q{Spread your tests over multiple machines to test your code faster.}
|
||||||
s.email = %q{nick@smartlogicsolutions.com}
|
s.email = %q{nick@smartlogicsolutions.com}
|
||||||
s.extra_rdoc_files = [
|
s.extra_rdoc_files = [
|
||||||
|
|
|
@ -32,6 +32,8 @@ module Hydra #:nodoc:
|
||||||
@listeners = []
|
@listeners = []
|
||||||
@verbose = opts.fetch('verbose') { false }
|
@verbose = opts.fetch('verbose') { false }
|
||||||
@report = opts.fetch('report') { false }
|
@report = opts.fetch('report') { false }
|
||||||
|
@autosort = opts.fetch('autosort') { true }
|
||||||
|
sort_files_from_report if @autosort
|
||||||
init_report_file
|
init_report_file
|
||||||
@sync = opts.fetch('sync') { nil }
|
@sync = opts.fetch('sync') { nil }
|
||||||
|
|
||||||
|
@ -56,6 +58,8 @@ module Hydra #:nodoc:
|
||||||
trace "Sending #{f.inspect}"
|
trace "Sending #{f.inspect}"
|
||||||
report_start_time(f)
|
report_start_time(f)
|
||||||
worker[:io].write(RunFile.new(:file => f))
|
worker[:io].write(RunFile.new(:file => f))
|
||||||
|
else
|
||||||
|
trace "No more files to send"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -186,30 +190,55 @@ module Hydra #:nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_report_file
|
def init_report_file
|
||||||
@report_file = File.join(Dir.tmpdir, 'hydra_report.txt')
|
FileUtils.rm_f(report_file)
|
||||||
FileUtils.rm_f(@report_file)
|
FileUtils.rm_f(report_results_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_start_time(file)
|
def report_start_time(file)
|
||||||
File.open(@report_file, 'a'){|f| f.write "#{file}|start|#{Time.now.to_f}\n" }
|
File.open(report_file, 'a'){|f| f.write "#{file}|start|#{Time.now.to_f}\n" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_finish_time(file)
|
def report_finish_time(file)
|
||||||
File.open(@report_file, 'a'){|f| f.write "#{file}|finish|#{Time.now.to_f}\n" }
|
File.open(report_file, 'a'){|f| f.write "#{file}|finish|#{Time.now.to_f}\n" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_report
|
def generate_report
|
||||||
report = {}
|
report = {}
|
||||||
lines = nil
|
lines = nil
|
||||||
File.open(@report_file, 'r'){|f| lines = f.read.split("\n")}
|
File.open(report_file, 'r'){|f| lines = f.read.split("\n")}
|
||||||
lines.each{|l| l = l.split('|'); report[l[0]] ||= {}; report[l[0]][l[1]] = l[2]}
|
lines.each{|l| l = l.split('|'); report[l[0]] ||= {}; report[l[0]][l[1]] = l[2]}
|
||||||
report.each{|file, times| report[file]['duration'] = times['finish'].to_f - times['start'].to_f}
|
report.each{|file, times| report[file]['duration'] = times['finish'].to_f - times['start'].to_f}
|
||||||
report = report.sort{|a, b| b[1]['duration'] <=> a[1]['duration']}
|
report = report.sort{|a, b| b[1]['duration'] <=> a[1]['duration']}
|
||||||
output = [""]
|
output = []
|
||||||
report.each{|file, times| output << "%.2f\t#{file}" % times['duration']}
|
report.each{|file, times| output << "%.2f\t#{file}" % times['duration']}
|
||||||
output << "Report available @ #{@report_file}"
|
|
||||||
@report_text = output.join("\n")
|
@report_text = output.join("\n")
|
||||||
|
File.open(report_results_file, 'w'){|f| f.write @report_text}
|
||||||
|
return report_text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reported_files
|
||||||
|
return [] unless File.exists?(report_results_file)
|
||||||
|
rep = []
|
||||||
|
File.open(report_results_file, 'r') do |f|
|
||||||
|
lines = f.read.split("\n")
|
||||||
|
lines.each{|l| rep << l.split(" ")[1] }
|
||||||
|
end
|
||||||
|
return rep
|
||||||
|
end
|
||||||
|
|
||||||
|
def sort_files_from_report
|
||||||
|
sorted_files = reported_files
|
||||||
|
reported_files.each do |f|
|
||||||
|
@files.push(@files.delete_at(@files.index(f))) if @files.index(f)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def report_file
|
||||||
|
@report_file ||= File.join(Dir.tmpdir, 'hydra_report.txt')
|
||||||
|
end
|
||||||
|
|
||||||
|
def report_results_file
|
||||||
|
@report_results_file ||= File.join(Dir.tmpdir, 'hydra_report_results.txt')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,8 +20,15 @@ module Hydra #:nodoc:
|
||||||
attr_accessor :config
|
attr_accessor :config
|
||||||
|
|
||||||
# Set to true if you want hydra to generate a report.
|
# Set to true if you want hydra to generate a report.
|
||||||
# Defaults to fals
|
# Defaults to false
|
||||||
attr_accessor :report
|
attr_accessor :report
|
||||||
|
|
||||||
|
# Automatically sort files using their historical runtimes.
|
||||||
|
# Defaults to true
|
||||||
|
# To disable:
|
||||||
|
# t.autosort = false
|
||||||
|
attr_accessor :autosort
|
||||||
|
|
||||||
#
|
#
|
||||||
# Search for the hydra config file
|
# Search for the hydra config file
|
||||||
def find_config_file
|
def find_config_file
|
||||||
|
@ -59,6 +66,7 @@ module Hydra #:nodoc:
|
||||||
@files = []
|
@files = []
|
||||||
@verbose = false
|
@verbose = false
|
||||||
@report = false
|
@report = false
|
||||||
|
@autosort = true
|
||||||
|
|
||||||
yield self if block_given?
|
yield self if block_given?
|
||||||
|
|
||||||
|
@ -67,6 +75,7 @@ module Hydra #:nodoc:
|
||||||
@opts = {
|
@opts = {
|
||||||
:verbose => @verbose,
|
:verbose => @verbose,
|
||||||
:report => @report,
|
:report => @report,
|
||||||
|
:autosort => @autosort,
|
||||||
:files => @files
|
:files => @files
|
||||||
}
|
}
|
||||||
if @config
|
if @config
|
||||||
|
@ -85,7 +94,7 @@ module Hydra #:nodoc:
|
||||||
task @name do
|
task @name do
|
||||||
$stdout.write "Hydra Testing #{files.inspect}\n"
|
$stdout.write "Hydra Testing #{files.inspect}\n"
|
||||||
h = Hydra::Master.new(@opts)
|
h = Hydra::Master.new(@opts)
|
||||||
$stdout.write h.report_text if @report
|
$stdout.write "\n"+h.report_text if @report
|
||||||
$stdout.write "\nHydra Completed\n"
|
$stdout.write "\nHydra Completed\n"
|
||||||
exit(0) #bypass test on_exit output
|
exit(0) #bypass test on_exit output
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ class MasterTest < Test::Unit::TestCase
|
||||||
context "with a file to test and a destination to verify" do
|
context "with a file to test and a destination to verify" do
|
||||||
setup do
|
setup do
|
||||||
# avoid having other tests interfering with us
|
# avoid having other tests interfering with us
|
||||||
sleep(0.25)
|
sleep(0.2)
|
||||||
FileUtils.rm_f(target_file)
|
FileUtils.rm_f(target_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue