Skip to content

Commit

Permalink
Make sure rollbacks occur within the scope of the task that triggered…
Browse files Browse the repository at this point in the history
… them

git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@4562 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed Jul 6, 2006
1 parent 5de92e8 commit 3d76d34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/capistrano/actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,16 @@ def transaction
logger.important "transaction: rollback", current ? current.name : "transaction start"
task_call_history.reverse.each do |task|
begin
# throw the task back on the stack so that roles are properly
# interpreted in the scope of the task in question.
push_task_call_frame(task.name)

logger.debug "rolling back", task.name
task.rollback.call if task.rollback
rescue Object => e
logger.info "exception while rolling back: #{e.class}, #{e.message}", task.name
ensure
pop_task_call_frame
end
end
raise
Expand Down
20 changes: 20 additions & 0 deletions test/actor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ class << @actor
assert_equal [:goodbye, :hello], @actor.history
end

def test_rollback_uses_roles_for_associated_task
@actor.define_task :inner, :roles => :db do
on_rollback { run "error" }
run "go"
raise "fail"
end

@actor.define_task :outer do
transaction do
inner
end
run "done"
end

assert_raise(RuntimeError) { @actor.outer }

assert TestingCommand.invoked?
assert_equal %w(01.example.com 02.example.com all.example.com), @actor.sessions.keys.sort
end

def test_delegates_to_configuration
@actor.define_task :hello do
delegated_method
Expand Down

0 comments on commit 3d76d34

Please sign in to comment.