mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Fix parallel command execution logging parallely - GH434
Also add unit tests that reproduce the problem
This commit is contained in:
parent
c4bd4c4e03
commit
a08fe0d67d
4 changed files with 48 additions and 8 deletions
1
Gemfile
1
Gemfile
|
@ -9,4 +9,5 @@ gemspec
|
||||||
#
|
#
|
||||||
group :development do
|
group :development do
|
||||||
gem "rake"
|
gem "rake"
|
||||||
|
gem "pry"
|
||||||
end
|
end
|
||||||
|
|
|
@ -163,10 +163,11 @@ module Capistrano
|
||||||
|
|
||||||
if tree.branches.any? || tree.fallback
|
if tree.branches.any? || tree.fallback
|
||||||
_, servers = filter_servers(options)
|
_, servers = filter_servers(options)
|
||||||
branches = servers.map{|server| tree.branches_for(server)}.compact
|
branches = branches_for_servers(tree,servers)
|
||||||
case branches.size
|
case branches.size
|
||||||
when 0
|
when 0
|
||||||
branches = tree.branches.dup + [tree.fallback]
|
branches = tree.branches.dup + [tree.fallback]
|
||||||
|
branches.compact!
|
||||||
case branches.size
|
case branches.size
|
||||||
when 1
|
when 1
|
||||||
logger.debug "no servers for #{branches.first}"
|
logger.debug "no servers for #{branches.first}"
|
||||||
|
@ -178,13 +179,7 @@ module Capistrano
|
||||||
logger.debug "executing #{branches.first}" unless options[:silent]
|
logger.debug "executing #{branches.first}" unless options[:silent]
|
||||||
else
|
else
|
||||||
logger.debug "executing multiple commands in parallel"
|
logger.debug "executing multiple commands in parallel"
|
||||||
branches.each {|maybe_branch|
|
branches.each {|branch| logger.trace "-> #{branch.to_s(true)}" }
|
||||||
if(maybe_branch.is_a?(Array))
|
|
||||||
maybe_branch.each {|branch| logger.trace "-> #{branch.to_s(true)}"}
|
|
||||||
else
|
|
||||||
logger.trace "-> #{maybe_branch.to_s(true)}"
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise ArgumentError, "attempt to execute without specifying a command"
|
raise ArgumentError, "attempt to execute without specifying a command"
|
||||||
|
@ -317,6 +312,17 @@ module Capistrano
|
||||||
exit(-1)
|
exit(-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def branches_for_servers(tree,servers)
|
||||||
|
servers.inject([]) do |branches,server|
|
||||||
|
if server_branches = tree.branches_for(server)
|
||||||
|
branches += server_branches
|
||||||
|
end
|
||||||
|
branches
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,7 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
||||||
attr_accessor :dry_run
|
attr_accessor :dry_run
|
||||||
attr_accessor :preserve_roles
|
attr_accessor :preserve_roles
|
||||||
attr_accessor :servers
|
attr_accessor :servers
|
||||||
|
attr_accessor :roles
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@options = {}
|
@options = {}
|
||||||
|
@ -226,6 +227,37 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
||||||
@config.invoke_command("ls", :once => true, :via => :foobar)
|
@config.invoke_command("ls", :once => true, :via => :foobar)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_parallel_command_execution_with_no_match
|
||||||
|
assert_block("should not raise argument error") do
|
||||||
|
begin
|
||||||
|
@config.parallel do |session|
|
||||||
|
session.when("in?(:app)", "ls") {|ch,stream,data| puts "noop"}
|
||||||
|
session.when("in?(:db)", "pwd") {|ch,stream,data| puts "noop"}
|
||||||
|
end
|
||||||
|
true
|
||||||
|
rescue
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parallel_command_execution_with_matching_servers
|
||||||
|
@config.expects(:execute_on_servers)
|
||||||
|
assert_block("should not raise Argument error") do
|
||||||
|
begin
|
||||||
|
@config.servers = [:app, :db]
|
||||||
|
@config.roles = {:app => [:app], :db => [:db] }
|
||||||
|
@config.parallel do |session|
|
||||||
|
session.when("in?(:app)", "ls") {|ch,stream,data| puts "noop"}
|
||||||
|
session.when("in?(:db)", "pwd") {|ch,stream,data| puts "noop"}
|
||||||
|
end
|
||||||
|
true
|
||||||
|
rescue
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def make_config
|
def make_config
|
||||||
|
|
|
@ -5,6 +5,7 @@ require 'test/unit'
|
||||||
require 'mocha'
|
require 'mocha'
|
||||||
|
|
||||||
require 'capistrano/server_definition'
|
require 'capistrano/server_definition'
|
||||||
|
require 'pry'
|
||||||
|
|
||||||
module TestExtensions
|
module TestExtensions
|
||||||
def server(host, options={})
|
def server(host, options={})
|
||||||
|
|
Loading…
Reference in a new issue