Commit f29e5dbc authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3ff29a16
......@@ -33,6 +33,7 @@ from persistent.timestamp import TimeStamp
import os, os.path, sys, subprocess
from errno import EINVAL
from golang import func, method, defer
from zodbtools.util import ashex as h
from pytest import raises
testdb = None
......@@ -120,7 +121,7 @@ def test_join_autostart():
assert os.path.isdir(wc.mountpoint + "/head/bigfile")
# XXX hack (tmp ?)
# XXX hack -> kill (?) or read-wait on head/at
# Conn._sync makes sure that underlying wcfs is synced to last ZODB data
@method(wcfs.Conn)
def _sync(self):
......@@ -144,7 +145,7 @@ def _sync(self):
# XXX parametrize zblk0, zblk1
# XXX select !wcfs mode so that we prepare data through !wcfs path.
@func
def test_bigfile_empty():
def test_bigfile_empty(): # XXX name
root = testdb.dbopen()
defer(lambda: dbclose(root))
......@@ -152,14 +153,25 @@ def test_bigfile_empty():
# NOTE there is no clean way to retrieve tid of just committed transaction
# we'll be using last._p_serial as workaround.
#
# we also store:
#
# Z.head - last committed transaction ID
# Z.tidv - [] of all committed tid↑
root['last'] = last = Persistent()
transaction.commit()
tid1 = last._p_serial
last._p_changed = 1
transaction.commit()
tid2 = last._p_serial
class _: pass
Z = _()
Z.tidv = []
def commit():
last._p_changed = 1
transaction.commit()
tid = last._p_serial
Z.head = tid
Z.tidv.append(tid)
return tid
tid1 = commit()
tid2 = commit()
assert tidtime(tid2) > tidtime(tid1)
wc = wcfs.join(testzurl, autostart=True)
......@@ -171,19 +183,19 @@ def test_bigfile_empty():
# lookup to non-BigFile - must be rejected
with raises(OSError) as exc:
os.stat("%s/%s" % (bigpath, last._p_oid.encode('hex')))
os.stat("%s/%s" % (bigpath, h(last._p_oid)))
assert exc.value.errno == EINVAL
# path to f under wcfs
fpath = "%s/%s" % (bigpath, f._p_oid.encode('hex'))
fpath = "%s/%s" % (bigpath, h(f._p_oid))
st = os.stat(fpath)
assert st.st_size == 0
assert st.st_mtime == tidtime(tid1)
# head/at = last txn of whole db
assert readfile(head + "/at") == tid2.encode('hex')
assert readfile(head + "/at") == h(tid2)
# TODO check head/at syncs to later non-bigfile commits
......@@ -196,9 +208,7 @@ def test_bigfile_empty():
s = b"hello world"
memcpy(vma, s)
last._p_changed = 1
transaction.commit()
tidlast = last._p_serial
commit()
# sync wcfs to ZODB
wc._sync()
......@@ -208,8 +218,8 @@ def test_bigfile_empty():
st = os.stat(fpath)
assert st.st_size == fsize
#assert st.st_mtime == tidtime(tidlast) FIXME proper sync
assert readfile(head + "/at") == tidlast.encode("hex")
#assert st.st_mtime == tidtime(Z.head) FIXME proper sync
assert readfile(head + "/at") == h(Z.head)
data = readfile(fpath)
assert len(data) == fsize
......@@ -221,7 +231,7 @@ def test_bigfile_empty():
# commit data again and make sure we can see both latest and snapshotted states.
tcommit1 = tidlast
tcommit1 = Z.head
fh = f.fileh_open()
vma1 = fh.mmap(hole, 1)
......@@ -231,9 +241,7 @@ def test_bigfile_empty():
memcpy(vma1,s1)
memcpy(vma2,s2)
last._p_changed = 1
transaction.commit()
tidlast = last._p_serial
commit()
wc._sync()
......@@ -242,8 +250,8 @@ def test_bigfile_empty():
st = os.stat(fpath)
assert st.st_size == fsize
#assert st.st_mtime == tidtime(tidlast) FIXME proper sync
assert readfile(head + "/at") == tidlast.encode("hex")
#assert st.st_mtime == tidtime(Z.head) FIXME proper sync
assert readfile(head + "/at") == h(Z.head)
data = readfile(fpath)
assert len(data) == fsize
......@@ -258,14 +266,14 @@ def test_bigfile_empty():
assert tail2[len(s2):] == b'\0'*(blksize - len(s2))
# path to f's state @tcommit1
rev1 = wc.mountpoint + ("/@%s" % tcommit1.encode("hex"))
fpath1 = rev1 + "/bigfile/" + f._p_oid.encode('hex')
rev1 = wc.mountpoint + ("/@%s" % h(tcommit1))
fpath1 = rev1 + "/bigfile/" + h(f._p_oid)
os.mkdir(rev1)
st = os.stat(fpath1)
assert st.st_size == fsize1
#assert st.st_mtime == tidtime(tcommit1) FIXME proper sync
#assert readfile(fpath + "/at") == tcommit1.encode("hex") XXX do we need it?
#assert readfile(fpath + "/at") == h(tcommit1) XXX do we need it?
data = readfile(fpath1)
assert len(data) == fsize1
......
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