hydra 0.10.3 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- = Hydra
1
+ = Hѱdra
2
2
 
3
3
  Spread your tests over multiple machines to test your code faster.
4
4
 
data/Rakefile CHANGED
@@ -49,4 +49,5 @@ Rake::RDocTask.new do |rdoc|
49
49
  rdoc.title = "hydra #{version}"
50
50
  rdoc.rdoc_files.include('README*')
51
51
  rdoc.rdoc_files.include('lib/**/*.rb')
52
+ rdoc.options << '--charset=utf-8'
52
53
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.3
1
+ 0.11.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hydra}
8
- s.version = "0.10.3"
8
+ s.version = "0.11.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nick Gauthier"]
12
- s.date = %q{2010-02-16}
12
+ s.date = %q{2010-02-17}
13
13
  s.description = %q{Spread your tests over multiple machines to test your code faster.}
14
14
  s.email = %q{nick@smartlogicsolutions.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "caliper.yml",
29
29
  "hydra.gemspec",
30
+ "hydra_gray.png",
30
31
  "lib/hydra.rb",
31
32
  "lib/hydra/hash.rb",
32
33
  "lib/hydra/master.rb",
Binary file
@@ -1,5 +1,6 @@
1
1
  require 'hydra/hash'
2
2
  require 'open3'
3
+ require 'tmpdir'
3
4
  module Hydra #:nodoc:
4
5
  # Hydra class responsible for delegate work down to workers.
5
6
  #
@@ -30,6 +31,8 @@ module Hydra #:nodoc:
30
31
  @workers = []
31
32
  @listeners = []
32
33
  @verbose = opts.fetch('verbose') { false }
34
+ @report = opts.fetch('report') { false }
35
+ init_report_file
33
36
  @sync = opts.fetch('sync') { nil }
34
37
 
35
38
  # default is one worker that is configured to use a pipe with one runner
@@ -49,8 +52,11 @@ module Hydra #:nodoc:
49
52
  # Send a file down to a worker.
50
53
  def send_file(worker)
51
54
  f = @files.shift
52
- trace "Sending #{f.inspect}"
53
- worker[:io].write(RunFile.new(:file => f)) if f
55
+ if f
56
+ trace "Sending #{f.inspect}"
57
+ report_start_time(f)
58
+ worker[:io].write(RunFile.new(:file => f))
59
+ end
54
60
  end
55
61
 
56
62
  # Process the results coming back from the worker.
@@ -59,6 +65,7 @@ module Hydra #:nodoc:
59
65
  # only delete one
60
66
  @incomplete_files.delete_at(@incomplete_files.index(message.file))
61
67
  trace "#{@incomplete_files.size} Files Remaining"
68
+ report_finish_time(message.file)
62
69
  if @incomplete_files.empty?
63
70
  shutdown_all_workers
64
71
  else
@@ -66,6 +73,9 @@ module Hydra #:nodoc:
66
73
  end
67
74
  end
68
75
 
76
+ # A text report of the time it took to run each file
77
+ attr_reader :report_text
78
+
69
79
  private
70
80
 
71
81
  def boot_workers(workers)
@@ -171,6 +181,35 @@ module Hydra #:nodoc:
171
181
  end
172
182
 
173
183
  @listeners.each{|l| l.join}
184
+
185
+ generate_report
186
+ end
187
+
188
+ def init_report_file
189
+ @report_file = File.join(Dir.tmpdir, 'hydra_report.txt')
190
+ FileUtils.rm_f(@report_file)
191
+ end
192
+
193
+ def report_start_time(file)
194
+ File.open(@report_file, 'a'){|f| f.write "#{file}|start|#{Time.now.to_f}\n" }
195
+ end
196
+
197
+ def report_finish_time(file)
198
+ File.open(@report_file, 'a'){|f| f.write "#{file}|finish|#{Time.now.to_f}\n" }
174
199
  end
200
+
201
+ def generate_report
202
+ report = {}
203
+ lines = nil
204
+ File.open(@report_file, 'r'){|f| lines = f.read.split("\n")}
205
+ lines.each{|l| l = l.split('|'); report[l[0]] ||= {}; report[l[0]][l[1]] = l[2]}
206
+ report.each{|file, times| report[file]['duration'] = times['finish'].to_f - times['start'].to_f}
207
+ report = report.sort{|a, b| b[1]['duration'] <=> a[1]['duration']}
208
+ output = [""]
209
+ report.each{|file, times| output << "%.2f\t#{file}" % times['duration']}
210
+ output << "Report available @ #{@report_file}"
211
+ @report_text = output.join("\n")
212
+ end
213
+
175
214
  end
176
215
  end
@@ -18,6 +18,10 @@ module Hydra #:nodoc:
18
18
  # Path to the hydra config file.
19
19
  # If not set, it will check 'hydra.yml' and 'config/hydra.yml'
20
20
  attr_accessor :config
21
+
22
+ # Set to true if you want hydra to generate a report.
23
+ # Defaults to fals
24
+ attr_accessor :report
21
25
  #
22
26
  # Search for the hydra config file
23
27
  def find_config_file
@@ -45,6 +49,7 @@ module Hydra #:nodoc:
45
49
  # t.add_files 'test/functional/**/*_test.rb'
46
50
  # t.add_files 'test/integration/**/*_test.rb'
47
51
  # t.verbose = false # optionally set to true for lots of debug messages
52
+ # t.report = true # optionally set to true for a final report of test times
48
53
  # end
49
54
  class TestTask < Hydra::Task
50
55
 
@@ -53,6 +58,7 @@ module Hydra #:nodoc:
53
58
  @name = name
54
59
  @files = []
55
60
  @verbose = false
61
+ @report = false
56
62
 
57
63
  yield self if block_given?
58
64
 
@@ -60,6 +66,7 @@ module Hydra #:nodoc:
60
66
 
61
67
  @opts = {
62
68
  :verbose => @verbose,
69
+ :report => @report,
63
70
  :files => @files
64
71
  }
65
72
  if @config
@@ -77,7 +84,8 @@ module Hydra #:nodoc:
77
84
  desc "Hydra Tests" + (@name == :hydra ? "" : " for #{@name}")
78
85
  task @name do
79
86
  $stdout.write "Hydra Testing #{files.inspect}\n"
80
- Hydra::Master.new(@opts)
87
+ h = Hydra::Master.new(@opts)
88
+ $stdout.write h.report_text if @report
81
89
  $stdout.write "\nHydra Completed\n"
82
90
  exit(0) #bypass test on_exit output
83
91
  end
@@ -20,6 +20,18 @@ class MasterTest < Test::Unit::TestCase
20
20
  assert_equal "HYDRA", File.read(target_file)
21
21
  end
22
22
 
23
+ should "generate a report" do
24
+ Hydra::Master.new(
25
+ :files => [test_file],
26
+ :report => true
27
+ )
28
+ assert File.exists?(target_file)
29
+ assert_equal "HYDRA", File.read(target_file)
30
+ report_file = File.join(Dir.tmpdir, 'hydra_report.txt')
31
+ assert File.exists?(report_file)
32
+ assert_equal 2, File.read(report_file).split("\n").size
33
+ end
34
+
23
35
  should "run a test 6 times on 1 worker with 2 runners" do
24
36
  Hydra::Master.new(
25
37
  :files => [test_file]*6,
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), 'test_helper')
3
3
  class RunnerTest < Test::Unit::TestCase
4
4
  context "with a file to test and a destination to verify" do
5
5
  setup do
6
+ sleep(0.2)
6
7
  FileUtils.rm_f(target_file)
7
8
  end
8
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Gauthier
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-16 00:00:00 -05:00
12
+ date: 2010-02-17 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -42,6 +42,7 @@ files:
42
42
  - VERSION
43
43
  - caliper.yml
44
44
  - hydra.gemspec
45
+ - hydra_gray.png
45
46
  - lib/hydra.rb
46
47
  - lib/hydra/hash.rb
47
48
  - lib/hydra/master.rb