Skip to content

Commit

Permalink
Pop transaction for transactions stack in case of code failure (excep…
Browse files Browse the repository at this point in the history
…tion)
  • Loading branch information
yrashk committed Apr 30, 2008
1 parent 762659c commit 212a1eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/strokedb/transaction.rb
Expand Up @@ -38,10 +38,15 @@ def execute
Thread.current[:strokedb_transactions].push self

@timestamp = LTS.new(store.timestamp.counter,uuid)

begin
result = yield(self)
rescue
throw $!
ensure
Thread.current[:strokedb_transactions].pop
end

result = yield(self)

Thread.current[:strokedb_transactions].pop

result
end
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/strokedb/stores/transaction_spec.rb
Expand Up @@ -65,6 +65,15 @@
Document.find(@doc.uuid).should be_nil
end

it "should pop transaction on code that raises some exception" do
lambda do
@txn.execute do |txn|
raise Exception
end
end.should raise_error(Exception)
Thread.current[:strokedb_transactions].should be_empty
end


end

Expand Down

0 comments on commit 212a1eb

Please sign in to comment.