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
        "nexedi/ZODB!1")
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

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