Commit 8d046f41 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f818193e
......@@ -134,8 +134,9 @@ class tDB:
t.tracked = set()
def close(t):
for tf in t.tracked:
for tf in t.tracked.copy():
tf.close()
assert len(t.tracked) == 0
t._wc_zheadfh.close()
t.wc.close()
dbclose(t.root)
......@@ -194,19 +195,15 @@ class tDB:
path = t.path(obj, at=at)
return os.stat(path)
# open opens file corresponding to obj on wcfs.
def open(t, obj, at=None):
# _open opens file corresponding to obj on wcfs.
def _open(t, obj, at=None):
path = t.path(obj, at=at)
return open(path, 'rb', 0) # unbuffered
# track starts to track wcfs file corresponding to zf@at.
# open opens wcfs file corresponding to zf@at and starts to track it.
# see returned tFile for details.
#
# XXX -> openfile? testopen?
def track(t, zf, at=None):
tf = tFile(t, zf, at=at)
t.tracked.add(tf)
return tf
def open(t, zf, at=None):
return tFile(t, zf, at=at)
# tFile is testing environment for one bigfile on wcfs.
class tFile:
......@@ -217,7 +214,7 @@ class tFile:
def __init__(t, tdb, zf, at=None):
assert isinstance(zf, ZBigFile)
t.tdb = tdb
t.f = tdb.open(zf, at=at)
t.f = tdb._open(zf, at=at)
t.blksize = zf.blksize
# mmap the file past the end up to XXX pages and lock the pages with
......@@ -228,8 +225,10 @@ class tFile:
t.fmmap = mm.map_ro(t.f.fileno(), 0, t._max_tracked*t.blksize)
mm.lock(t.fmmap, mm.MLOCK_ONFAULT)
tdb.tracked.add(t)
def close(t):
# XXX remove from t.tdb.tracked
t.tdb.tracked.remove(t)
mm.unmap(t.fmmap)
t.f.close()
......@@ -247,7 +246,7 @@ class tFile:
@func
def readblk(t, zf, blk, at=None):
assert isinstance(zf, ZBigFile)
f = t.open(zf, at=at) # XXX binary, !buffered
f = t._open(zf, at=at) # XXX binary, !buffered
defer(f.close)
blksize = zf.blksize
......@@ -351,29 +350,27 @@ def test_wcfs():
t.stat(nonfile)
assert exc.value.errno == EINVAL
f = t.track(zf) # XXX -> testopen, fileopen?
f = t.open(zf)
# file initially empty
f.assertCache([])
f.assertData ([], mtime=tid1)
# commit data to zf and make sure we can see it on wcfs
# use !wcfs mode so that we prepare data independently of wcfs code paths.
# commit data to zf -> verify we can see it on wcfs
# (use !wcfs mode so that we prepare data independently of wcfs code paths)
zfh = zf.fileh_open(_use_wcfs=False)
vma = zfh.mmap(2, 1) # 1 page at offset=2
s = b"hello world"
memcpy(vma, s)
t.commit()
t.wcsync() # sync wcfs to ZODB
t.wcsync()
f.assertCache([0,0,0]) # initially not cached
f.assertData ([b'',b'',s], mtime=t.head)
# XXX assertCache all present?
# commit data again and make sure we can see both latest and snapshotted states.
tcommit1 = t.head
# commit data again -> verify we can see both latest and snapshotted states.
at1 = t.head
zfh = zf.fileh_open(_use_wcfs=False)
vma1 = zfh.mmap(2, 1)
......@@ -382,18 +379,26 @@ def test_wcfs():
s2 = b"alpha"
memcpy(vma1,s1)
memcpy(vma2,s2)
t.commit()
t.wcsync()
# f @head
f.assertCache([1,1,0,0]) # XXX fails here (.size changed)
f.assertCache([1,1,0,0])
f.assertData ([b'',b'', s1+b'ld', s2], mtime=t.head)
# f @tcommit1
f1 = t.track(zf, at=tcommit1)
# f @at1
f1 = t.open(zf, at=at1)
f1.assertCache([0,0,1])
f1.assertData ([b'',b'',s]) # XXX + mtime=tcommit1?
f1.assertData ([b'',b'',s]) # XXX + mtime=at1?
# f @head is opened again -> cache must not be lost
f.assertCache([1,1,1,1])
f_ = t.open(zf)
f_.assertCache([1,1,1,1])
f_.close()
f.assertCache([1,1,1,1])
def test_wcfs_invproto():
......
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