Commit db98563c authored by Adam Groszer's avatar Adam Groszer

added test to check tryToResolveConflict log output

parent bdc633a8
......@@ -292,6 +292,75 @@ And load the pickle:
>>> db2.close()
"""
def show_tryToResolveConflict_log_output():
"""
Verify output generated by tryToResolveConflict in the logs
>>> db = ZODB.DB('t.fs') # FileStorage!
>>> storage = db.storage
>>> conn = db.open()
>>> conn.root.x = ResolveableWhenStateDoesNotChange()
>>> conn.root.x.v = 1
>>> transaction.commit()
>>> serial1 = conn.root.x._p_serial
>>> conn.root.x.v = 2
>>> transaction.commit()
>>> serial2 = conn.root.x._p_serial
>>> oid = conn.root.x._p_oid
Install a log handler to be able to show log entries
>>> import logging
>>> from zope.testing.loggingsupport import InstalledHandler
>>> handler = InstalledHandler('ZODB.ConflictResolution',
... level=logging.DEBUG)
We conflict if both the committed and new are different than the original:
>>> p = storage.tryToResolveConflict(
... oid, serial2, serial1, storage.loadSerial(oid, serial2))
... # doctest: +ELLIPSIS
Traceback (most recent call last):
...
ConflictError: database conflict error (oid 0x01, ...
If content doesn't support conflict resolution:
>>> conn.root.y = Unresolvable()
>>> conn.root.y.v = 1
>>> transaction.commit()
>>> oid = conn.root.y._p_oid
>>> serial = conn.root.y._p_serial
>>> p = storage.tryToResolveConflict(
... oid, serial, serial, storage.loadSerial(oid, serial))
... # doctest: +ELLIPSIS
Traceback (most recent call last):
...
ConflictError: database conflict error (oid 0x02, ...
Let's see what went into the log:
>>> len(handler.records)
2
>>> import six
>>> msg = handler.records[0]
>>> six.print_(msg.name, msg.levelname, msg.getMessage())
ZODB.ConflictResolution ERROR Unexpected error
>>> msg = handler.records[1]
>>> six.print_(msg.name, msg.levelname, msg.getMessage())
ZODB.ConflictResolution DEBUG Conflict resolution failed with ConflictError: database conflict error
Cleanup:
>>> handler.uninstall()
>>> db.close()
"""
def test_suite():
return unittest.TestSuite([
manuel.testing.TestSuite(
......
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