diff --git a/lib/hydra/master.rb b/lib/hydra/master.rb index 5200a41..fdea5de 100644 --- a/lib/hydra/master.rb +++ b/lib/hydra/master.rb @@ -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 diff --git a/lib/hydra/tmpdir.rb b/lib/hydra/tmpdir.rb new file mode 100644 index 0000000..1c75adb --- /dev/null +++ b/lib/hydra/tmpdir.rb @@ -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 \ No newline at end of file diff --git a/lib/hydra/worker.rb b/lib/hydra/worker.rb index b4f7b47..c0b6f2b 100644 --- a/lib/hydra/worker.rb +++ b/lib/hydra/worker.rb @@ -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,7 +29,15 @@ 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 # When a runner wants a file, it hits this method with a message. diff --git a/test/fixtures/features/step_definitions.rb b/test/fixtures/features/step_definitions.rb index 08f6487..a27365c 100644 --- a/test/fixtures/features/step_definitions.rb +++ b/test/fixtures/features/step_definitions.rb @@ -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| diff --git a/test/fixtures/write_file.rb b/test/fixtures/write_file.rb index 76fcd35..0d76ab8 100644 --- a/test/fixtures/write_file.rb +++ b/test/fixtures/write_file.rb @@ -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 diff --git a/test/fixtures/write_file_alternate_spec.rb b/test/fixtures/write_file_alternate_spec.rb index d3fbb0e..e3ef5ac 100644 --- a/test/fixtures/write_file_alternate_spec.rb +++ b/test/fixtures/write_file_alternate_spec.rb @@ -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 diff --git a/test/fixtures/write_file_spec.rb b/test/fixtures/write_file_spec.rb index 60ece30..be2f4c8 100644 --- a/test/fixtures/write_file_spec.rb +++ b/test/fixtures/write_file_spec.rb @@ -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 diff --git a/test/fixtures/write_file_with_pending_spec.rb b/test/fixtures/write_file_with_pending_spec.rb index f37d444..10f30af 100644 --- a/test/fixtures/write_file_with_pending_spec.rb +++ b/test/fixtures/write_file_with_pending_spec.rb @@ -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 diff --git a/test/master_test.rb b/test/master_test.rb index 18b1611..2177102 100644 --- a/test/master_test.rb +++ b/test/master_test.rb @@ -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} diff --git a/test/sync_test.rb b/test/sync_test.rb index f98a435..998ab87 100644 --- a/test/sync_test.rb +++ b/test/sync_test.rb @@ -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} diff --git a/test/test_helper.rb b/test/test_helper.rb index 63b38a8..96c65bd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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