From c9b0c3215ee2740435aae0d76a943c6ea812375f Mon Sep 17 00:00:00 2001 From: Luke Melia Date: Wed, 9 Jun 2010 14:24:32 -0400 Subject: [PATCH] Work around an issue where Dir.tmpdir under OS X behaves differently when in an SSH session and from the console --- lib/hydra/master.rb | 4 ++-- lib/hydra/tmpdir.rb | 11 +++++++++++ test/fixtures/features/step_definitions.rb | 4 ++-- test/fixtures/write_file.rb | 2 +- test/fixtures/write_file_alternate_spec.rb | 4 ++-- test/fixtures/write_file_spec.rb | 4 ++-- test/fixtures/write_file_with_pending_spec.rb | 2 +- test/master_test.rb | 9 +++++---- test/sync_test.rb | 10 +++++----- test/test_helper.rb | 4 ++-- 10 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 lib/hydra/tmpdir.rb diff --git a/lib/hydra/master.rb b/lib/hydra/master.rb index 837d78f..ca8cbed 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' @@ -238,7 +238,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/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 543858a..7033be8 100644 --- a/test/fixtures/write_file_alternate_spec.rb +++ b/test/fixtures/write_file_alternate_spec.rb @@ -1,8 +1,8 @@ -require 'tmpdir' +require 'hydra/tmpdir' require 'spec' 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 ea617f0..6ffd2b6 100644 --- a/test/fixtures/write_file_spec.rb +++ b/test/fixtures/write_file_spec.rb @@ -1,8 +1,8 @@ -require 'tmpdir' +require 'hydra/tmpdir' require 'spec' 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 3399ada..ccd8790 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 'spec' 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..8d1725f 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] @@ -88,7 +88,8 @@ class MasterTest < Test::Unit::TestCase :connect => 'localhost', :directory => File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')), :runners => 1 - }] + }], + :verbose => true ) assert File.exists?(target_file) assert_equal "HYDRA", File.read(target_file) @@ -104,8 +105,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