Commit d8409616 authored by Julien Muchembled's avatar Julien Muchembled

Update 'synchronizers' tests wrt to transaction 1.6.1

Changes are backported from commits 227953b9
and 03a326be.
parent 5ad423e4
......@@ -25,11 +25,27 @@ Make a change locally:
>>> rt = cn.root()
>>> rt['a'] = 1
Sync should not have been called yet.
Sync isn't called when a connection is opened, even though that
implicitly starts a new transaction:
>>> st.sync_called # False before 3.4
>>> st.sync_called
False
Sync is called when we explicitly start a new transaction:
>>> _ = transaction.begin()
>>> st.sync_called
True
>>> st.sync_called = False
BTW, calling ``sync()`` on a connection starts a new transaction, which
caused ``sync()`` to be called on the storage:
>>> cn.sync()
>>> st.sync_called
True
>>> st.sync_called = False
``sync()`` is called by the Connection's ``afterCompletion()`` hook after the
commit completes.
......@@ -62,42 +78,14 @@ traceback then ;-)
>>> cn.close()
One more, very obscure. It was the case that if the first action a new
threaded transaction manager saw was a ``begin()`` call, then synchronizers
registered after that in the same transaction weren't communicated to the
`Transaction` object, and so the synchronizers' ``afterCompletion()`` hooks
weren't called when the transaction commited. None of the test suites
(ZODB's, Zope 2.8's, or Zope3's) caught that, but apparently Zope 3 takes this
path at some point when serving pages.
As a special case, if a synchronizer registers while a transaction is
in flight, then newTransaction and thus the storage sync method is
called:
>>> tm = transaction.ThreadTransactionManager()
>>> st.sync_called = False
>>> dummy = tm.begin() # we're doing this _before_ opening a connection
>>> cn = db.open(transaction_manager=tm)
>>> rt = cn.root() # make a change
>>> rt['c'] = 3
>>> st.sync_called
False
Now ensure that ``cn.afterCompletion() -> st.sync()`` gets called by commit
despite that the `Connection` registered after the transaction began:
>>> tm.commit()
>>> st.sync_called
True
And try the same thing with a non-threaded transaction manager:
>>> cn.close()
>>> tm = transaction.TransactionManager()
>>> st.sync_called = False
>>> dummy = tm.begin() # we're doing this _before_ opening a connection
>>> _ = tm.begin() # we're doing this _before_ opening a connection
>>> cn = db.open(transaction_manager=tm)
>>> rt = cn.root() # make a change
>>> rt['d'] = 4
>>> st.sync_called
False
>>> tm.commit()
>>> st.sync_called
True
......
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