Commit 583b2853 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 027f9a6b
......@@ -17,13 +17,15 @@
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
from wendelin.lib.zodb import LivePersistent, deactivate_btree, dbclose
from wendelin.lib.zodb import LivePersistent, deactivate_btree, dbclose, zconn_at
from wendelin.lib.testing import getTestDB
from persistent import Persistent, UPTODATE, GHOST, CHANGED
from ZODB import DB, POSException
from BTrees.IOBTree import IOBTree
import transaction
from transaction import TransactionManager
from golang import defer, func
from pytest import raises
import gc
testdb = None
......@@ -228,7 +230,46 @@ def test_deactivate_btree():
assert obj not in cached
# zsync syncs ZODB storage.
# it is noop, if zstor does not support syncing (i.e. FileStorage has no .sync())
def zsync(zstor):
sync = getattr(zstor, 'sync', None)
if sync is not None:
sync()
@func
def test_zconn_at():
stor = testdb.getZODBStorage()
defer(stor.close)
db = DB(stor)
zsync(stor)
at0 = stor.lastTransaction()
# open connection, it must be viewing the database @at0
conn1 = db.open()
assert zconn_at(conn1) == at0
# commit
root1 = conn1.root()
root1['z'] = 1
transaction.commit()
# after commit the view is updated
zsync(stor)
at1 = stor.lastTransaction()
assert zconn_at(conn1) == at1 # still at at0 XXX ok?
# reopen -> view @at1
conn1.close()
with raises(POSException.ConnectionStateError):
zconn_at(conn1)
conn2 = db.open()
assert conn2 is conn1 # returned from DB pool
assert zconn_at(conn2) == at1
conn2.close()
# TODO commit -> know head -> open conn1,
# open conn2, commit there; wait or sync, make sure zconn_at(conn1) is as expected
......
......@@ -22,6 +22,7 @@
import ZODB
from ZODB.FileStorage import FileStorage
from ZODB import DB
from ZODB import POSException
from ZODB.utils import p64, u64
from persistent import Persistent
from weakref import WeakSet
......@@ -141,7 +142,8 @@ def _deactivate_bucket(bucket):
# zconn_at returns tid as of which ZODB connection is viewing the database.
def zconn_at(zconn): # -> tid
assert isinstance(zconn, ZODB.Connection.Connection)
# XXX assert zconn is opened
if zconn.opened is None: # zconn must be in "opened" state
raise POSException.ConnectionStateError("database connection is closed")
# ZODB5 uses MVCC uniformly
if zmajor >= 5:
......
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