Permalink
Browse files

add remote_base_dir to sync_options to specify where working copies a…

…re stored remotely
  • Loading branch information...
1 parent d1b1a57 commit c9a000ebcf5d61d8660336e39de4c1a44270289e @qxjit committed Aug 4, 2009
View
@@ -131,7 +131,8 @@ below in your Rakefile.
t.distributed_hosts = %w[host1 host2]
t.sync_options = {
:source => <absolute path of project root on machine>,
- :username => "username"
+ :username => "username",
+ :remote_base_dir => <absolute path to keep working copies in on remote machine> # defaults to /tmp
}
end
View
@@ -48,7 +48,8 @@ DeepTest::TestTask.new(:distributed_test) do |t|
t.pattern = "test/**/*_test.rb"
t.distributed_hosts = %w[localhost]
t.sync_options = {:source => File.dirname(__FILE__),
- :rsync_options => "--exclude=.svn"}
+ :rsync_options => "--exclude=.svn",
+ :remote_base_dir => "/tmp/deep_test"}
end
Spec::Rake::SpecTask.new(:spec) do |t|
@@ -6,7 +6,7 @@
STDIN.close
beachhead_port = DeepTest::Distributed::Beachhead.new(
- File.join(options.mirror_path('/tmp'), File.basename(options.sync_options[:source])),
+ File.join(options.mirror_path, File.basename(options.sync_options[:source])),
options
).daemonize
@@ -6,8 +6,7 @@ def initialize(config)
end
def push_code(options)
- path = options.mirror_path(@config[:work_dir])
- RSync.push(@config[:address], options.sync_options, path)
+ RSync.push(@config[:address], options.sync_options, options.mirror_path)
end
def establish_beachhead(options)
@@ -49,7 +48,7 @@ def ssh_command(options)
def spawn_command(options)
"#{ShellEnvironment.like_login} && " +
- "cd #{options.mirror_path(@config[:work_dir])} && " +
+ "cd #{options.mirror_path} && " +
"OPTIONS=#{options.to_command_line} " +
"ruby lib/deep_test/distributed/establish_beachhead.rb"
end
@@ -78,10 +78,10 @@ def to_command_line
Base64.encode64(Marshal.dump(self)).gsub("\n","")
end
- def mirror_path(base)
+ def mirror_path
raise "No source directory specified in sync_options" unless sync_options[:source]
relative_mirror_path = @origin_hostname + sync_options[:source].gsub('/','_')
- "#{base}/#{relative_mirror_path}"
+ "#{sync_options[:remote_base_dir] || '/tmp'}/#{relative_mirror_path}"
end
def new_deployment
@@ -94,7 +94,7 @@ def new_deployment
def new_landing_fleet
landing_ships = distributed_hosts.map do |host|
- Distributed::LandingShip.new :address => host, :work_dir => '/tmp'
+ Distributed::LandingShip.new :address => host
end
Distributed::LandingFleet.new self, landing_ships
end
@@ -172,20 +172,25 @@ class FakeUI; end
yielded_wire.should == :wire
end
- it "should be able to calculate mirror_path based on base an sync_options" do
+ it "should be able to calculate mirror_path based on sync_options" do
Socket.should_receive(:gethostname).and_return("hostname")
- options = Options.new(:sync_options => {:source => "/my/source/path"})
- options.mirror_path("/mirror/base/path").should ==
- "/mirror/base/path/hostname_my_source_path"
+ options = Options.new(:sync_options => {:source => "/my/source/path", :remote_base_dir => "/mirror/base/path"})
+ options.mirror_path.should == "/mirror/base/path/hostname_my_source_path"
end
it "should raise a useful error if no source is specified" do
- options = DeepTest::Options.new(:sync_options => {})
+ options = DeepTest::Options.new(:sync_options => {:remote_base_dir => "/mirror/base/path/"})
lambda {
- options.mirror_path("base")
+ options.mirror_path
}.should raise_error("No source directory specified in sync_options")
end
+ it "should default to /tmp if no remote_base_dir is specified in sync_options" do
+ Socket.should_receive(:gethostname).and_return("hostname")
+ options = DeepTest::Options.new(:sync_options => {:source => "/my/source/path"})
+ options.mirror_path.should == "/tmp/hostname_my_source_path"
+ end
+
it "should be gathering metrics if metrics file is set" do
options = DeepTest::Options.new(:metrics_file => "filename")
options.should be_gathering_metrics
@@ -6,7 +6,7 @@ module Distributed
test "generates a local working copy path based on host and source of request" do
Socket.stubs(:gethostname).returns("myhost")
Telegraph::Wire.stubs(:connect).returns :wire
- landing_ship = LandingShip.new(:address => "host", :work_dir => "/tmp")
+ landing_ship = LandingShip.new(:address => "host")
options = Options.new(:sync_options => {:source => "/my/local/dir"})
RSync.expects(:push).with("host", options.sync_options, "/tmp/myhost_my_local_dir")
landing_ship.push_code(options)
@@ -15,7 +15,7 @@ module Distributed
test "establish_beachhead launches beachhead process on remote machine" do
Socket.stubs(:gethostname).returns("myhost")
Telegraph::Wire.stubs(:connect).returns :wire
- landing_ship = LandingShip.new(:address => "remote_host", :work_dir => "/tmp")
+ landing_ship = LandingShip.new(:address => "remote_host")
options = Options.new(:sync_options => {:source => "/my/local/dir"})
landing_ship.expects(:`).with(
@@ -31,7 +31,7 @@ module Distributed
test "establish_beachhead launches beachhead process on remote machine with usernames specified in sync_options" do
Socket.stubs(:gethostname).returns("myhost")
Telegraph::Wire.stubs(:connect).returns :wire
- landing_ship = LandingShip.new(:address => "remote_host", :work_dir => "/tmp")
+ landing_ship = LandingShip.new(:address => "remote_host")
options = Options.new(:sync_options => {:username => "me", :source => "/my/local/dir"})
landing_ship.expects(:`).with(

0 comments on commit c9a000e

Please sign in to comment.