hydra 0.7.0 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/hydra.gemspec +3 -2
- data/lib/hydra.rb +1 -0
- data/lib/hydra/master.rb +7 -2
- data/lib/hydra/messaging_io.rb +1 -1
- data/lib/hydra/runner.rb +6 -3
- data/lib/hydra/safe_fork.rb +23 -0
- data/lib/hydra/ssh.rb +6 -1
- data/lib/hydra/trace.rb +1 -1
- data/lib/hydra/worker.rb +3 -4
- data/test/fixtures/echo_the_dolphin.rb +2 -2
- data/test/runner_test.rb +6 -1
- data/test/ssh_test.rb +10 -16
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.2
|
data/hydra.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hydra}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.2"
|
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-
|
12
|
+
s.date = %q{2010-02-05}
|
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 = [
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/hydra/messaging_io.rb",
|
38
38
|
"lib/hydra/pipe.rb",
|
39
39
|
"lib/hydra/runner.rb",
|
40
|
+
"lib/hydra/safe_fork.rb",
|
40
41
|
"lib/hydra/ssh.rb",
|
41
42
|
"lib/hydra/stdio.rb",
|
42
43
|
"lib/hydra/trace.rb",
|
data/lib/hydra.rb
CHANGED
data/lib/hydra/master.rb
CHANGED
@@ -23,6 +23,7 @@ module Hydra #:nodoc:
|
|
23
23
|
opts.merge!(YAML.load_file(config_file).stringify_keys!)
|
24
24
|
end
|
25
25
|
@files = opts.fetch('files') { [] }
|
26
|
+
@files.sort!{|a,b| File.size(b) <=> File.size(a)} # dumb heuristic
|
26
27
|
@incomplete_files = @files.dup
|
27
28
|
@workers = []
|
28
29
|
@listeners = []
|
@@ -83,7 +84,7 @@ module Hydra #:nodoc:
|
|
83
84
|
runners = worker.fetch('runners') { raise "You must specify the number of runners" }
|
84
85
|
trace "Booting local worker"
|
85
86
|
pipe = Hydra::Pipe.new
|
86
|
-
child =
|
87
|
+
child = SafeFork.fork do
|
87
88
|
pipe.identify_as_child
|
88
89
|
Hydra::Worker.new(:io => pipe, :runners => runners, :verbose => @verbose)
|
89
90
|
end
|
@@ -129,7 +130,11 @@ module Hydra #:nodoc:
|
|
129
130
|
begin
|
130
131
|
message = worker[:io].gets
|
131
132
|
trace "got message: #{message}"
|
132
|
-
|
133
|
+
# if it exists and its for me.
|
134
|
+
# SSH gives us back echoes, so we need to ignore our own messages
|
135
|
+
if message and !message.class.to_s.index("Worker").nil?
|
136
|
+
message.handle(self, worker)
|
137
|
+
end
|
133
138
|
rescue IOError
|
134
139
|
trace "lost Worker [#{worker.inspect}]"
|
135
140
|
Thread.exit
|
data/lib/hydra/messaging_io.rb
CHANGED
@@ -13,7 +13,7 @@ module Hydra #:nodoc:
|
|
13
13
|
return nil unless message
|
14
14
|
return Message.build(eval(message.chomp))
|
15
15
|
rescue SyntaxError, NameError
|
16
|
-
|
16
|
+
#$stderr.write "Not a message: [#{message.inspect}]\n"
|
17
17
|
return gets
|
18
18
|
end
|
19
19
|
|
data/lib/hydra/runner.rb
CHANGED
@@ -66,7 +66,7 @@ module Hydra #:nodoc:
|
|
66
66
|
while @running
|
67
67
|
begin
|
68
68
|
message = @io.gets
|
69
|
-
if message
|
69
|
+
if message and !message.class.to_s.index("Worker").nil?
|
70
70
|
trace "Received message from worker"
|
71
71
|
trace "\t#{message.inspect}"
|
72
72
|
message.handle(self)
|
@@ -92,9 +92,12 @@ module Hydra #:nodoc:
|
|
92
92
|
eval(c.first)
|
93
93
|
end
|
94
94
|
rescue NameError
|
95
|
-
|
95
|
+
# means we could not load [c.first], but thats ok, its just not
|
96
|
+
# one of the classes we want to test
|
97
|
+
nil
|
96
98
|
rescue SyntaxError
|
97
|
-
|
99
|
+
# see above
|
100
|
+
nil
|
98
101
|
end
|
99
102
|
end
|
100
103
|
return klasses.select{|k| k.respond_to? 'suite'}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class SafeFork
|
2
|
+
def self.fork
|
3
|
+
begin
|
4
|
+
# remove our connection so it doesn't get cloned
|
5
|
+
ActiveRecord::Base.remove_connection if defined?(ActiveRecord)
|
6
|
+
# fork a process
|
7
|
+
child = Process.fork do
|
8
|
+
begin
|
9
|
+
# create a new connection and perform the action
|
10
|
+
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
# make sure we remove the connection before we're done
|
14
|
+
ActiveRecord::Base.remove_connection if defined?(ActiveRecord)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
ensure
|
18
|
+
# make sure we re-establish the connection before returning to the main instance
|
19
|
+
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
|
20
|
+
end
|
21
|
+
return child
|
22
|
+
end
|
23
|
+
end
|
data/lib/hydra/ssh.rb
CHANGED
@@ -24,9 +24,14 @@ module Hydra #:nodoc:
|
|
24
24
|
# Hydra::SSH.new('-p 3022 user@server.com')
|
25
25
|
# etc..
|
26
26
|
def initialize(connection_options, directory, command)
|
27
|
-
@writer, @reader, @error = popen3("ssh #{connection_options}")
|
27
|
+
@writer, @reader, @error = popen3("ssh -tt #{connection_options}")
|
28
28
|
@writer.write("cd #{directory}\n")
|
29
29
|
@writer.write(command+"\n")
|
30
30
|
end
|
31
|
+
|
32
|
+
def close
|
33
|
+
@writer.write "exit\n"
|
34
|
+
super
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
data/lib/hydra/trace.rb
CHANGED
@@ -16,7 +16,7 @@ module Hydra #:nodoc:
|
|
16
16
|
# Trace some output with the class's prefix and a newline.
|
17
17
|
# Checks to ensure we're running verbosely.
|
18
18
|
def trace(str)
|
19
|
-
$stdout.write "#{self.class._traceable_prefix}| #{str}\n" if @verbose
|
19
|
+
$stdout.write "#{Time.now.to_f} #{self.class._traceable_prefix}| #{str}\n" if @verbose
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/hydra/worker.rb
CHANGED
@@ -68,7 +68,7 @@ module Hydra #:nodoc:
|
|
68
68
|
trace "Booting #{num_runners} Runners"
|
69
69
|
num_runners.times do
|
70
70
|
pipe = Hydra::Pipe.new
|
71
|
-
child =
|
71
|
+
child = SafeFork.fork do
|
72
72
|
pipe.identify_as_child
|
73
73
|
Hydra::Runner.new(:io => pipe, :verbose => @verbose)
|
74
74
|
end
|
@@ -98,7 +98,7 @@ module Hydra #:nodoc:
|
|
98
98
|
while @running
|
99
99
|
begin
|
100
100
|
message = @io.gets
|
101
|
-
if message
|
101
|
+
if message and !message.class.to_s.index("Master").nil?
|
102
102
|
trace "Received Message from Master"
|
103
103
|
trace "\t#{message.inspect}"
|
104
104
|
message.handle(self)
|
@@ -120,7 +120,7 @@ module Hydra #:nodoc:
|
|
120
120
|
while @running
|
121
121
|
begin
|
122
122
|
message = r[:io].gets
|
123
|
-
if message
|
123
|
+
if message and !message.class.to_s.index("Runner").nil?
|
124
124
|
trace "Received Message from Runner"
|
125
125
|
trace "\t#{message.inspect}"
|
126
126
|
message.handle(self, r)
|
@@ -139,7 +139,6 @@ module Hydra #:nodoc:
|
|
139
139
|
idle_r = nil
|
140
140
|
while idle_r.nil?
|
141
141
|
idle_r = @runners.detect{|runner| runner[:idle]}
|
142
|
-
sleep(1)
|
143
142
|
end
|
144
143
|
return idle_r
|
145
144
|
end
|
data/test/runner_test.rb
CHANGED
@@ -38,16 +38,21 @@ class RunnerTest < Test::Unit::TestCase
|
|
38
38
|
ssh = Hydra::SSH.new(
|
39
39
|
'localhost',
|
40
40
|
File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')),
|
41
|
-
"ruby -e \"require 'rubygems'; require 'hydra'; Hydra::Runner.new(:io => Hydra::Stdio.new);\""
|
41
|
+
"ruby -e \"require 'rubygems'; require 'hydra'; Hydra::Runner.new(:io => Hydra::Stdio.new, :verbose => true);\""
|
42
42
|
)
|
43
43
|
assert ssh.gets.is_a?(Hydra::Messages::Runner::RequestFile)
|
44
44
|
ssh.write(Hydra::Messages::Worker::RunFile.new(:file => test_file))
|
45
45
|
|
46
46
|
# grab its response. This makes us wait for it to finish
|
47
|
+
echo = ssh.gets # get the ssh echo
|
47
48
|
response = ssh.gets
|
49
|
+
|
50
|
+
assert_equal Hydra::Messages::Runner::Results, response.class
|
48
51
|
|
49
52
|
# tell it to shut down
|
50
53
|
ssh.write(Hydra::Messages::Worker::Shutdown.new)
|
54
|
+
|
55
|
+
ssh.close
|
51
56
|
|
52
57
|
# ensure it ran
|
53
58
|
assert File.exists?(target_file)
|
data/test/ssh_test.rb
CHANGED
@@ -1,21 +1,15 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
3
|
class SSHTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@ssh.close
|
15
|
-
end
|
16
|
-
should "be able to execute a command" do
|
17
|
-
@ssh.write @message
|
18
|
-
assert_equal @message.text, @ssh.gets.text
|
19
|
-
end
|
4
|
+
should "be able to execute a command over ssh" do
|
5
|
+
ssh = Hydra::SSH.new(
|
6
|
+
'localhost', # connect to this machine
|
7
|
+
File.expand_path(File.join(File.dirname(__FILE__))), # move to the test directory
|
8
|
+
"ruby fixtures/echo_the_dolphin.rb"
|
9
|
+
)
|
10
|
+
message = Hydra::Messages::TestMessage.new
|
11
|
+
ssh.write message
|
12
|
+
assert_equal message.text, ssh.gets.text
|
13
|
+
ssh.close
|
20
14
|
end
|
21
15
|
end
|
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.7.
|
4
|
+
version: 0.7.2
|
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-
|
12
|
+
date: 2010-02-05 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/hydra/messaging_io.rb
|
63
63
|
- lib/hydra/pipe.rb
|
64
64
|
- lib/hydra/runner.rb
|
65
|
+
- lib/hydra/safe_fork.rb
|
65
66
|
- lib/hydra/ssh.rb
|
66
67
|
- lib/hydra/stdio.rb
|
67
68
|
- lib/hydra/trace.rb
|