Skip to content

Commit

Permalink
Handle errors a bit better, sensing a race condition on DRb.start_ser…
Browse files Browse the repository at this point in the history
…vice.

Also removed redundant daemon descriptor munging, delegating all that
to DeploymentDescriptor, verifying that ruby version is set as
well. This means the client can omit certain unimportant attributes
and we'll fill them in for 'em.
  • Loading branch information
jcrossley3 committed Jun 11, 2011
1 parent 1102c84 commit 4bc5487
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
26 changes: 10 additions & 16 deletions lib/torquespec/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def initialize(opts={})
def start
puts "JC: start daemon"
DRb.start_service("druby://127.0.0.1:#{TorqueSpec.drb_port}", self)
10.times do
if DRb.current_server
break
else
sleep(0.1)
end
end
end

def stop
Expand All @@ -47,6 +54,8 @@ def run(reporter)
begin
eval_before_alls(new)
run_remotely(reporter)
rescue Exception => ex
fail_filtered_examples(ex, reporter)
ensure
eval_after_alls(new)
end
Expand All @@ -56,30 +65,15 @@ def run(reporter)
def run_remotely(reporter)
DRb.start_service("druby://127.0.0.1:0")
daemon = DRbObject.new_with_uri("druby://127.0.0.1:#{TorqueSpec.drb_port}")
# TODO: maybe fall back to local if can't run?
begin
daemon.run( name, reporter )
rescue Exception
puts $!, $@
ensure
DRb.stop_service
end
end

def deploy_paths
descriptor = <<-END.gsub(/^ {10}/,'')
application:
root: #{TorqueSpec.app_root}
ruby:
version: #{RUBY_VERSION[0,3]}
services:
TorqueSpec::Daemon:
argv: #{TorqueSpec.argv}
pwd: #{Dir.pwd}
environment:
RUBYLIB: #{TorqueSpec.rubylib}
END
[ DeploymentDescriptor.new(descriptor, display_name).path ]
[ DeploymentDescriptor.new({}, display_name, true).path ]
end

end
Expand Down
21 changes: 14 additions & 7 deletions lib/torquespec/deployment_descriptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(descriptor, name, daemonify = false)
FileUtils.mkdir_p(TorqueSpec.knob_root) unless File.exist?(TorqueSpec.knob_root)
end
def path
daemonify( hash || filename || heredoc )
verify( hash || filename || heredoc )
end
def hash
if @descriptor.is_a? Hash
Expand All @@ -38,21 +38,28 @@ def stringify_keys(x)
x.is_a?(Hash) ? x.inject({}) {|h,(k,v)| h[k.to_s] = stringify_keys(v); h} : x
end

def daemonify( path )
if @daemonify
yaml = YAML.load_file( path )
if yaml.is_a? Hash
def verify( path )
original = YAML.load_file( path )
if original.is_a? Hash
yaml = original.dup
if @daemonify
yaml['application'] ||= {}
yaml['application']['root'] ||= TorqueSpec.app_root
yaml['services'] ||= {}
yaml['services'].update( 'TorqueSpec::Daemon' => { 'argv' => TorqueSpec.argv, 'pwd' => Dir.pwd } )
yaml['environment'] ||= {}
env = { 'RUBYLIB' => TorqueSpec.rubylib }
yaml['environment'].update(env) {|k,oldval,newval| "#{oldval}:#{newval}"}
end
yaml['ruby'] ||= {}
yaml['ruby']['version'] ||= RUBY_VERSION[0,3]
if original != yaml
File.open( path, 'w' ) do |file|
YAML.dump( yaml, file )
end
else
$stderr.puts "WARN: Unable to decorate your deployment descriptor with TorqueSpec::Daemon"
end
else
$stderr.puts "WARN: Unable to decorate your deployment descriptor with TorqueSpec::Daemon"
end
path
end
Expand Down

0 comments on commit 4bc5487

Please sign in to comment.