Commit 1da89b57 authored by Kirill Smelkov's avatar Kirill Smelkov

wcfs: tests: Teach tDB to create database with initial ZBigFile changes before WCFS is started

This semantically moves initialization code from
test_wcfs_basic_invalidation_wo_dFtail_coverage (see a7bf0311 "wcfs: Fix
crash if on invalidation handledδZ needs to access ZODB") to tDB itself,
and will be useful to exercise similar scenarios in other tests.

Still crashing in test_wcfs_watch_setup.
parent 339f1884
...@@ -394,8 +394,13 @@ class tWCFS(_tWCFS): ...@@ -394,8 +394,13 @@ class tWCFS(_tWCFS):
class tDB(tWCFS): class tDB(tWCFS):
# __init__ initializes test database and wcfs.
#
# old_data can be optinally provided to specify ZBigFile revisions to
# create before wcfs startup. old_data is []changeDelta - see .commit
# and .change for details.
@func @func
def __init__(t, _with_old_data=False): def __init__(t, old_data=[]):
t.root = testdb.dbopen() t.root = testdb.dbopen()
def _(): # close/unlock db if __init__ fails def _(): # close/unlock db if __init__ fails
exc = sys.exc_info()[1] exc = sys.exc_info()[1]
...@@ -416,17 +421,15 @@ class tDB(tWCFS): ...@@ -416,17 +421,15 @@ class tDB(tWCFS):
t._maintid = gettid() t._maintid = gettid()
# prepare initial objects for test: zfile, nonzfile # prepare initial objects for test: zfile, nonzfile
if not _with_old_data:
t.root['!file'] = t.nonzfile = Persistent() t.root['!file'] = t.nonzfile = Persistent()
t.root['zfile'] = t.zfile = ZBigFile(blksize) t.root['zfile'] = t.zfile = ZBigFile(blksize)
t.at0 = t._commit() t.at0 = t._commit()
else:
t.at0 = tAt(t, t.tail)
t.nonzfile = t.root['!file'] # commit initial data before wcfs starts
t.zfile = t.root['zfile'] for changeDelta in old_data:
t._commit(t.zfile, changeDelta)
# start wcfs after testdb is created # start wcfs after testdb is created and initial data is committed
super(tDB, t).__init__() super(tDB, t).__init__()
# fh(.wcfs/zhead) + history of zhead read from there # fh(.wcfs/zhead) + history of zhead read from there
...@@ -1324,21 +1327,13 @@ def test_wcfs_basic_read_aftertail(): ...@@ -1324,21 +1327,13 @@ def test_wcfs_basic_read_aftertail():
# invalidations if it needs to access ZODB during handleδZ. # invalidations if it needs to access ZODB during handleδZ.
@func @func
def test_wcfs_basic_invalidation_wo_dFtail_coverage(): def test_wcfs_basic_invalidation_wo_dFtail_coverage():
# prepare initial data with single change to zfile[0]. # start wcfs with ΔFtail/ΔBtail not covering initial data.
@func t = tDB(old_data=[{0:'a'}]); zf = t.zfile
def _():
t = tDB(); zf = t.zfile
defer(t.close)
t.commit(zf, {0:'a'})
_()
# start wcfs with ΔFtail/ΔBtail not covering that initial change.
t = tDB(_with_old_data=True); zf = t.zfile
defer(t.close) defer(t.close)
f = t.open(zf) f = t.open(zf)
t.commit(zf, {1:'b1'}) # arbitrary commit to non-0 blk t.commit(zf, {1:'b1'}) # arbitrary commit to non-0 blk
f._assertBlk(0, 'a') # [0] becomes tracked (don't verify against computed dataok due to _with_old_data) f.assertBlk(0, 'a') # [0] becomes tracked
# wcfs was crashing on processing further invalidation to blk 0 because # wcfs was crashing on processing further invalidation to blk 0 because
# - ΔBtail.GetAt([0], head) returns valueExact=false, and so # - ΔBtail.GetAt([0], head) returns valueExact=false, and so
......
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