Skip to content

Commit

Permalink
Add additional hooks for subclasses
Browse files Browse the repository at this point in the history
Fixes #22

Also some minor refactoring with an eye towards speed and simplicity.
We get between 5 and 10% faster, even accounting for all the overhead
of raising exceptions:

+----------------+---------------+------------------------------+
| Benchmark      | masterresults | issue22results               |
+================+===============+==============================+
| trivial commit | 14.9 us       | 13.2 us: 1.12x faster (-11%) |
+----------------+---------------+------------------------------+
| max retries    | 16.0 us       | 15.1 us: 1.06x faster (-5%)  |
+----------------+---------------+------------------------------+
  • Loading branch information
jamadden committed Sep 5, 2019
1 parent 464c32e commit 0a04f5a
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 133 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Expand Up @@ -16,6 +16,12 @@
retried. Previously, an error there would probably be raised
*anyway* and not retried, unless a subclass had made customizations.

- Add ``setUp`` and ``tearDown`` methods to TransactionLoop to give
subclasses a place to hook into the inners of the transaction loop.
This is particularly helpful if they need to do something after the
transaction manager has been put in explicit mode. See `issue 22
<https://github.com/NextThought/nti.transactions/issues/22>`_.

2.0.1 (2019-09-03)
==================

Expand Down
10 changes: 5 additions & 5 deletions src/nti/transactions/tests/test_transaction.py
Expand Up @@ -40,7 +40,7 @@ class RaisingCommit(object):
def __init__(self, t=Exception):
self.t = t

def commit(self):
def nti_commit(self):
if self.t:
raise self.t

Expand Down Expand Up @@ -186,7 +186,7 @@ def test_note(self, fake_begin, fake_get):
fake_tx = fudge.Fake()
(fake_tx
.expects('note').with_args(u'Hi')
.expects('abort')
.expects('nti_abort')
.provides('isDoomed').returns(True))
fake_begin.expects_call().returns(fake_tx)
fake_get.expects_call().returns(fake_tx)
Expand All @@ -202,7 +202,7 @@ def describe_transaction(self, *args, **kwargs):
'transaction._manager.TransactionManager.get')
def test_abort_no_side_effect(self, fake_begin, fake_get):
fake_tx = fudge.Fake()
fake_tx.expects('abort')
fake_tx.expects('nti_abort')

fake_begin.expects_call().returns(fake_tx)
fake_get.expects_call().returns(fake_tx)
Expand All @@ -214,7 +214,7 @@ class Loop(TransactionLoop):
result = Loop(lambda: 42)()
assert_that(result, is_(42))

@fudge.patch('transaction._transaction.Transaction.abort')
@fudge.patch('transaction._transaction.Transaction.nti_abort')
def test_abort_doomed(self, fake_abort):
fake_abort.expects_call()

Expand All @@ -230,7 +230,7 @@ def handler():
'transaction._manager.TransactionManager.get')
def test_abort_veto(self, fake_begin, fake_get):
fake_tx = fudge.Fake()
fake_tx.expects('abort')
fake_tx.expects('nti_abort')
fake_tx.provides('isDoomed').returns(False)

fake_begin.expects_call().returns(fake_tx)
Expand Down

0 comments on commit 0a04f5a

Please sign in to comment.