Merge branch 'weplay'

Conflicts:
	test/fixtures/write_file_alternate_spec.rb
	test/fixtures/write_file_spec.rb
This commit is contained in:
Nick Gauthier 2010-09-02 16:08:08 -05:00
commit 3fd1401513
11 changed files with 41 additions and 21 deletions

View File

@ -1,6 +1,6 @@
require 'hydra/hash'
require 'open3'
require 'tmpdir'
require 'hydra/tmpdir'
require 'erb'
require 'yaml'
@ -232,7 +232,7 @@ module Hydra #:nodoc:
end
def heuristic_file
@heuristic_file ||= File.join(Dir.tmpdir, 'hydra_heuristics.yml')
@heuristic_file ||= File.join(Dir.consistent_tmpdir, 'hydra_heuristics.yml')
end
end
end

11
lib/hydra/tmpdir.rb Normal file
View File

@ -0,0 +1,11 @@
require 'tmpdir'
class Dir
def self.consistent_tmpdir
if RUBY_PLATFORM =~ /darwin/i
'/tmp' # OS X normally returns a crazy tmpdir, BUT when logged in via SSH, it is '/tmp'. This unifies it.
else
Dir.tmpdir
end
end
end

View File

@ -20,6 +20,7 @@ module Hydra #:nodoc:
@runners = []
@listeners = []
load_worker_initializer
boot_runners(opts.fetch(:runners) { 1 })
@io.write(Hydra::Messages::Worker::WorkerBegin.new)
@ -28,6 +29,14 @@ module Hydra #:nodoc:
@runners.each{|r| Process.wait r[:pid] }
end
def load_worker_initializer
if File.exist?('./hydra_worker_init.rb')
trace('Requiring hydra_worker_init.rb')
require 'hydra_worker_init'
else
trace('hydra_worker_init.rb not present')
end
end
# message handling methods

View File

@ -1,9 +1,9 @@
Given /^a target file$/ do
@target_file = File.expand_path(File.join(Dir.tmpdir, 'hydra_test.txt'))
@target_file = File.expand_path(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'))
end
Given /^an alternate target file$/ do
@target_file = File.expand_path(File.join(Dir.tmpdir, 'alternate_hydra_test.txt'))
@target_file = File.expand_path(File.join(Dir.consistent_tmpdir, 'alternate_hydra_test.txt'))
end
When /^I write "([^\"]*)" to the file$/ do |text|

View File

@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
class WriteFileTest < Test::Unit::TestCase
def test_write_a_file
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f|
File.open(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'), 'a') do |f|
f.write "HYDRA"
end
end

View File

@ -1,8 +1,8 @@
require 'tmpdir'
require 'rspec'
require 'hydra/tmpdir'
context "file writing" do
it "writes to a file" do
File.open(File.join(Dir.tmpdir, 'alternate_hydra_test.txt'), 'a') do |f|
File.open(File.join(Dir.consistent_tmpdir, 'alternate_hydra_test.txt'), 'a') do |f|
f.write "HYDRA"
end
end

View File

@ -1,8 +1,8 @@
require 'tmpdir'
require 'rspec'
require 'hydra/tmpdir'
context "file writing" do
it "writes to a file" do
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f|
File.open(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'), 'a') do |f|
f.write "HYDRA"
end
end

View File

@ -2,7 +2,7 @@ require 'tmpdir'
require 'rspec'
context "file writing" do
it "writes to a file" do
File.open(File.join(Dir.tmpdir, 'hydra_test.txt'), 'a') do |f|
File.open(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'), 'a') do |f|
f.write "HYDRA"
end
end

View File

@ -35,7 +35,7 @@ class MasterTest < Test::Unit::TestCase
Hydra::Master.new(:files => [test_file])
assert File.exists?(target_file)
assert_equal "HYDRA", File.read(target_file)
report_file = File.join(Dir.tmpdir, 'hydra_heuristics.yml')
report_file = File.join(Dir.consistent_tmpdir, 'hydra_heuristics.yml')
assert File.exists?(report_file)
assert report = YAML.load_file(report_file)
assert_not_nil report[test_file]
@ -104,8 +104,8 @@ class MasterTest < Test::Unit::TestCase
end
should "synchronize a test file over ssh with rsync" do
local = File.join(Dir.tmpdir, 'hydra', 'local')
remote = File.join(Dir.tmpdir, 'hydra', 'remote')
local = File.join(Dir.consistent_tmpdir, 'hydra', 'local')
remote = File.join(Dir.consistent_tmpdir, 'hydra', 'remote')
sync_test = File.join(File.dirname(__FILE__), 'fixtures', 'sync_test.rb')
[local, remote].each{|f| FileUtils.rm_rf f; FileUtils.mkdir_p f}

View File

@ -13,8 +13,8 @@ class SyncTest < Test::Unit::TestCase
end
should "synchronize a test file over ssh with rsync" do
local = File.join(Dir.tmpdir, 'hydra', 'local')
remote = File.join(Dir.tmpdir, 'hydra', 'remote')
local = File.join(Dir.consistent_tmpdir, 'hydra', 'local')
remote = File.join(Dir.consistent_tmpdir, 'hydra', 'remote')
sync_test = File.join(File.dirname(__FILE__), 'fixtures', 'sync_test.rb')
[local, remote].each{|f| FileUtils.rm_rf f; FileUtils.mkdir_p f}
@ -58,9 +58,9 @@ class SyncTest < Test::Unit::TestCase
end
should "synchronize a test file over ssh with rsync to multiple workers" do
local = File.join(Dir.tmpdir, 'hydra', 'local')
remote_a = File.join(Dir.tmpdir, 'hydra', 'remote_a')
remote_b = File.join(Dir.tmpdir, 'hydra', 'remote_b')
local = File.join(Dir.consistent_tmpdir, 'hydra', 'local')
remote_a = File.join(Dir.consistent_tmpdir, 'hydra', 'remote_a')
remote_b = File.join(Dir.consistent_tmpdir, 'hydra', 'remote_b')
sync_test = File.join(File.dirname(__FILE__), 'fixtures', 'sync_test.rb')
[local, remote_a, remote_b].each{|f| FileUtils.rm_rf f; FileUtils.mkdir_p f}

View File

@ -12,11 +12,11 @@ Test::Unit.run = false
class Test::Unit::TestCase
def target_file
File.expand_path(File.join(Dir.tmpdir, 'hydra_test.txt'))
File.expand_path(File.join(Dir.consistent_tmpdir, 'hydra_test.txt'))
end
def alternate_target_file
File.expand_path(File.join(Dir.tmpdir, 'alternate_hydra_test.txt'))
File.expand_path(File.join(Dir.consistent_tmpdir, 'alternate_hydra_test.txt'))
end
def test_file