Commit 8287b988 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e5203906
...@@ -116,6 +116,7 @@ def test_join_autostart(): ...@@ -116,6 +116,7 @@ def test_join_autostart():
# tDB is database/wcfs testing environment. # tDB is database/wcfs testing environment.
# XXX + tFile ?
class tDB: class tDB:
def __init__(t): def __init__(t):
t.root = testdb.dbopen() t.root = testdb.dbopen()
...@@ -193,6 +194,7 @@ class tDB: ...@@ -193,6 +194,7 @@ class tDB:
return open(path) return open(path)
# readblk reads ZBigFile[blk] from wcfs. # readblk reads ZBigFile[blk] from wcfs.
# XXX not needed?
@func @func
def readblk(t, zf, blk, at=None): def readblk(t, zf, blk, at=None):
assert isinstance(zf, ZBigFile) assert isinstance(zf, ZBigFile)
...@@ -211,18 +213,28 @@ class tDB: ...@@ -211,18 +213,28 @@ class tDB:
return data return data
# assertData asserts that wcfs file corresponding to zf has data blocks as specified in expectv. # assertFile asserts that wcfs file corresponding to zf has data blocks as specified.
# #
# Expected blocks may be given with size < zf.blksize. In such case they # Expected blocks may be given with size < zf.blksize. In such case they
# are implicitly appended with trailing zeros. # are implicitly appended with trailing zeros.
def assertData(t, zf, expectv, at=None): #
# It also check file size and optionally mtime.
#
# XXX also check pagecache state?
def assertFile(t, zf, blkv, mtime=None, at=None):
assert isinstance(zf, ZBigFile) assert isinstance(zf, ZBigFile)
st = t.stat(zf, at=at)
assert st.st_size == len(blkv)*zf.blksize
if mtime is not None:
assert st.st_mtime == tidtime(mtime)
data = t.read(zf, at=at) data = t.read(zf, at=at)
assert len(data) == len(expectv)*zf.blksize assert len(data) == len(blkv)*zf.blksize
for i, blk in enumerate(expectv): for i, blk in enumerate(blkv):
assert len(blk) <= zf.blksize assert len(blk) <= zf.blksize
blk += b'\0'*(zf.blksize - len(blk)) # trailing zeros blk += b'\0'*(zf.blksize - len(blk)) # trailing zeros
assert data[i*zf.blksize:(i+1)*zf.blksize] == blk assert data[i*zf.blksize:(i+1)*zf.blksize] == blk, ("#blk: %d" % i)
...@@ -262,25 +274,8 @@ def test_wcfs(): ...@@ -262,25 +274,8 @@ def test_wcfs():
t.commit() t.commit()
t.wcsync() # sync wcfs to ZODB t.wcsync() # sync wcfs to ZODB
fsize = (hole + 1)*blksize # size is always mutiple of blksize. # XXX assert cache = ø
_ = t.stat(f) t.assertFile(f, [b'']*hole + [s], mtime=t.head)
assert _.st_size == fsize
assert _.st_mtime == tidtime(t.head)
t.assertData(f, [b'']*hole + [s])
for i in range(hole):
assert t.readblk(f, i) == b'\0'*blksize
assert t.readblk(f, hole) == s + b'\0'*(blksize - len(s))
data = t.read(f)
assert len(data) == fsize
for i in range(hole):
assert data[i*blksize:(i+1)*blksize] == b'\0'*blksize
tail = data[hole*blksize:]
assert tail[:len(s)] == s
assert tail[len(s):] == b'\0'*(blksize - len(s))
# commit data again and make sure we can see both latest and snapshotted states. # commit data again and make sure we can see both latest and snapshotted states.
...@@ -297,39 +292,13 @@ def test_wcfs(): ...@@ -297,39 +292,13 @@ def test_wcfs():
t.commit() t.commit()
t.wcsync() t.wcsync()
fsize1 = fsize # f @head
fsize = fsize1 + blksize # we added one more block # XXX assert cache
t.assertFile(f, [b'']*hole + [s1+b'ld', s2], mtime=t.head)
_ = t.stat(f)
assert _.st_size == fsize
assert _.st_mtime == tidtime(t.head)
data = t.read(f)
assert len(data) == fsize
for i in range(hole):
assert data[i*blksize:(i+1)*blksize] == b'\0'*blksize
tail1 = data[hole*blksize:(hole+1)*blksize]
assert tail1[:len(s1)] == s1
assert tail1[len(s1):len(s)] == "ld"
assert tail1[len(s):] == b'\0'*(blksize - len(s))
tail2 = data[(hole+1)*blksize:]
assert tail2[:len(s2)] == s2
assert tail2[len(s2):] == b'\0'*(blksize - len(s2))
# f @tcommit1 # f @tcommit1
st = t.stat(f, at=tcommit1) # XXX assert cache
assert st.st_size == fsize1 t.assertFile(f, [b'']*hole + [s], at=tcommit1) # XXX + mtime=tcommit1?
#assert st.st_mtime == tidtime(tcommit1) FIXME mtime for @revX -> = revX ?
#assert readfile(fpath + "/at") == h(tcommit1) XXX do we need it?
data = t.read(f, at=tcommit1)
assert len(data) == fsize1
for i in range(hole):
assert data[i*blksize:(i+1)*blksize] == b'\0'*blksize
tail = data[hole*blksize:]
assert tail[:len(s)] == s
assert tail[len(s):] == b'\0'*(blksize - len(s))
# TODO pagecache state after loading (via mincore) # TODO pagecache state after loading (via mincore)
......
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