Commit b6916ca8 authored by Kirill Smelkov's avatar Kirill Smelkov

fixup! *: Use defer for dbclose & friends

In 5c8340d2 we said:

    dbclose now uses defer almost everywhere - there are still few places in
    tests, where one test function is opening/closing test database multiple
    times - those were not (yet ?) converted.

Let's convert those remaining places now, because when wendelin.core
tests are run wrt plain ZODB4 (contrary to ZODB4-wc2), many tests fail
at fileh_open time, e.g.

        @func
        def test_bigfile_filezodb_fileh_gc():
            root1= dbopen()
            conn1= root1._p_jar
            db   = conn1.db()
            defer(db.close)
            root1['zfile4'] = f1 = ZBigFile(blksize)
            transaction.commit()

    >       fh1  = f1.fileh_open()

    bigfile/tests/test_filezodb.py:588:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    bigfile/file_zodb.py:603: in fileh_open
        fileh = _ZBigFileH(self, _use_wcfs)
    bigfile/file_zodb.py:664: in __init__
        self.zfileh = zfile._v_file.fileh_open(use_wcfs)
    bigfile/_file_zodb.pyx:112: in wendelin.bigfile._file_zodb._ZBigFile.fileh_open
        pywconn   = wczsync.pywconnOf(zconn)
    wcfs/client/_wczsync.pyx:56: in wendelin.wcfs.client._wczsync.pywconnOf
        wconn = wc.connect(zconn_at(zconn))
    lib/zodb.py:163: in zconn_at
        "ZODB!1")
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    patch = 'conn:MVCC-via-loadBefore-only', details_link = 'ZODB!1'

        def _zassertHasNXDPatch(patch, details_link):
            if not _zhasNXDPatch(patch):
                raise AssertionError(
                    "ZODB%s is not patched with required Nexedi patch %r\n\tSee %s for details" %
    >               (zmajor, patch, details_link))
    E           AssertionError: ZODB4 is not patched with required Nexedi patch 'conn:MVCC-via-loadBefore-only'
    E               See ZODB!1 for details

and DB is left unclosed.

This change should reduce, if not completely fix, the number of
leaked /tmp/testdb_* directories for Wendelin.core.UnitTest-ZODB4(xfail) testsuite.
parent c5624fa9
......@@ -44,13 +44,15 @@ def teardown_module():
testdb.teardown()
@func
def test_zbigarray():
root = testdb.dbopen()
defer(lambda: dbclose(root))
root['zarray'] = ZBigArray((16*1024*1024,), uint8)
transaction.commit()
dbclose(root)
del root
root = testdb.dbopen()
......@@ -94,7 +96,7 @@ def test_zbigarray():
# reload DB & array
dbclose(root)
del root, a,b, A
del a,b, A
root = testdb.dbopen()
......@@ -130,7 +132,7 @@ def test_zbigarray():
# reload & verify changes
dbclose(root)
del root, a, A, db
del a, A, db
root = testdb.dbopen()
......@@ -165,7 +167,7 @@ def test_zbigarray():
# commit; reload & verify changes
transaction.commit()
dbclose(root)
del root, a, b, A
del a, b, A
root = testdb.dbopen()
......@@ -190,22 +192,21 @@ def test_zbigarray():
assert a[24*1024*1024+2] == 12
assert a[24*1024*1024+3] == 13
dbclose(root)
# test array ordering is saved properly into DB and is picked up in
# backward-compatible manner - for data saved before order parameter was
# introduced.
# (actual ordering indexing test is in BigArray tests, not here)
@func
def test_zbigarray_order():
# make sure order is properly saved/restored to/from DB
root = testdb.dbopen()
defer(lambda: dbclose(root))
root['carray'] = ZBigArray((16*1024*1024,), uint8)
root['farray'] = ZBigArray((16*1024*1024,), uint8, order='F')
transaction.commit()
dbclose(root)
del root
root = testdb.dbopen()
C = root['carray']
......@@ -228,16 +229,12 @@ def test_zbigarray_order():
transaction.commit()
dbclose(root)
del root, Cold
root = testdb.dbopen()
Cold = root['coldarray']
assert Cold._order == 'C'
dbclose(root)
del root
# the same as test_bigfile_filezodb_vs_conn_migration but explicitly for ZBigArray
......
......@@ -74,10 +74,12 @@ blksize32 = blksize // 4
def Blk(vma, i):
return ndarray(blksize32, offset=i*blksize, buffer=vma, dtype=uint32)
@func
def test_bigfile_filezodb():
ram_reclaim_all() # reclaim pages allocated by previous tests
root = dbopen()
defer(lambda: dbclose(root))
root['zfile'] = f = ZBigFile(blksize)
transaction.commit()
......@@ -124,7 +126,6 @@ def test_bigfile_filezodb():
del fh
dbclose(root)
del root
root = dbopen()
f = root['zfile']
......@@ -160,7 +161,6 @@ def test_bigfile_filezodb():
del vma
del fh
dbclose(root)
del root
root = dbopen()
f = root['zfile']
......@@ -194,7 +194,7 @@ def test_bigfile_filezodb():
del vma
del fh
dbclose(root)
del db, root
del db
root = dbopen()
f = root['zfile']
......@@ -209,9 +209,6 @@ def test_bigfile_filezodb():
assert array_equal(Blk(vma, i)[1:], dataX(i)[1:])
dbclose(root)
# connection can migrate between threads handling requests.
# verify _ZBigFileH properly adjusts.
......
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