Commit 3275904a authored by Jim Fulton's avatar Jim Fulton Committed by GitHub

Merge pull request #16 from zopefoundation/notify_data_managers_that_join_transactions_in_progress

Notify data managers that join transactions in progress
parents 4e472621 53a51d35
Changes Changes
======= =======
1.6.1 (unreleased)
------------------
- Fixed: Synchonizers that registered with transaction managers when
transactions were in progress didn't have their newTransaction
methods called to let them know of the in-progress transactions.
1.6.0 (2016-05-21) 1.6.0 (2016-05-21)
------------------ ------------------
......
[buildout] [buildout]
develop = . develop = .
parts = test parts = py
[test] [test]
recipe = zc.recipe.testrunner recipe = zc.recipe.testrunner
eggs = transaction eggs = transaction [test]
[py]
recipe = zc.recipe.egg
eggs = ${test:eggs}
interpreter = py
...@@ -11,14 +11,13 @@ ...@@ -11,14 +11,13 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
version = '1.6.0' version = '1.6.1.dev0'
import os import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__)) here = os.path.abspath(os.path.dirname(__file__))
def _read_file(filename): def _read_file(filename):
with open(os.path.join(here, filename)) as f: with open(os.path.join(here, filename)) as f:
return f.read() return f.read()
...@@ -26,6 +25,8 @@ def _read_file(filename): ...@@ -26,6 +25,8 @@ def _read_file(filename):
README = _read_file('README.rst') + '\n\n' + _read_file('CHANGES.rst') README = _read_file('README.rst') + '\n\n' + _read_file('CHANGES.rst')
tests_require = ['mock']
setup(name='transaction', setup(name='transaction',
version=version, version=version,
description='Transaction management for Python', description='Transaction management for Python',
...@@ -58,15 +59,14 @@ setup(name='transaction', ...@@ -58,15 +59,14 @@ setup(name='transaction',
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
test_suite="transaction.tests", test_suite="transaction.tests",
tests_require = [ tests_require = tests_require,
'zope.interface',
],
install_requires=[ install_requires=[
'zope.interface', 'zope.interface',
], ],
extras_require = { extras_require = {
'docs': ['Sphinx', 'repoze.sphinx.autointerface'], 'docs': ['Sphinx', 'repoze.sphinx.autointerface'],
'testing': ['nose', 'coverage'], 'test': tests_require,
'testing': ['nose', 'coverage'] + tests_require,
}, },
entry_points = """\ entry_points = """\
""" """
......
...@@ -89,6 +89,8 @@ class TransactionManager(object): ...@@ -89,6 +89,8 @@ class TransactionManager(object):
""" See ITransactionManager. """ See ITransactionManager.
""" """
self._synchs.add(synch) self._synchs.add(synch)
if self._txn is not None:
synch.newTransaction(self._txn)
def unregisterSynch(self, synch): def unregisterSynch(self, synch):
""" See ITransactionManager. """ See ITransactionManager.
......
...@@ -65,6 +65,10 @@ class ITransactionManager(Interface): ...@@ -65,6 +65,10 @@ class ITransactionManager(Interface):
Synchronizers are notified about some major events in a transaction's Synchronizers are notified about some major events in a transaction's
life. See ISynchronizer for details. life. See ISynchronizer for details.
If a synchronizer registers while there is an active
transaction, its newTransaction method will be called with the
active transaction.
""" """
def unregisterSynch(synch): def unregisterSynch(synch):
......
...@@ -442,6 +442,27 @@ class TransactionManagerTests(unittest.TestCase): ...@@ -442,6 +442,27 @@ class TransactionManagerTests(unittest.TestCase):
assert nosub1._p_jar.ctpc_abort == 1 assert nosub1._p_jar.ctpc_abort == 1
def test_notify_transaction_late_comers(self):
# If a datamanager registers for synchonization after a
# transaction has started, we should call newTransaction so it
# can do necessry setup.
import mock
from .. import TransactionManager
manager = TransactionManager()
sync1 = mock.MagicMock()
manager.registerSynch(sync1)
sync1.newTransaction.assert_not_called()
t = manager.begin()
sync1.newTransaction.assert_called_with(t)
sync2 = mock.MagicMock()
manager.registerSynch(sync2)
sync2.newTransaction.assert_called_with(t)
# for, um, completeness
t.commit()
for s in sync1, sync2:
s.beforeCompletion.assert_called_with(t)
s.afterCompletion.assert_called_with(t)
class AttemptTests(unittest.TestCase): class AttemptTests(unittest.TestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment