Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
b04ae81a
Commit
b04ae81a
authored
Mar 15, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d022326d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
29 deletions
+64
-29
wcfs/wcfs_test.py
wcfs/wcfs_test.py
+64
-29
No files found.
wcfs/wcfs_test.py
View file @
b04ae81a
...
...
@@ -117,7 +117,6 @@ def test_join_autostart():
# tDB is database/wcfs testing environment.
# XXX + tFile ?
class
tDB
:
def
__init__
(
t
):
t
.
root
=
testdb
.
dbopen
()
...
...
@@ -131,11 +130,17 @@ class tDB:
t
.
_wc_zheadfh
=
open
(
t
.
wc
.
mountpoint
+
"/.wcfs/zhead"
)
t
.
_wc_zheadv
=
[]
# tracked tFiles
t
.
tracked
=
set
()
def
close
(
t
):
for
tf
in
t
.
tracked
:
tf
.
close
()
t
.
_wc_zheadfh
.
close
()
t
.
wc
.
close
()
dbclose
(
t
.
root
)
# commit commits transaction and remembers/returns committed transaction ID.
def
commit
(
t
):
# NOTE there is no clean way to retrieve tid of just committed transaction
...
...
@@ -194,6 +199,25 @@ class tDB:
path
=
t
.
path
(
obj
,
at
=
at
)
return
open
(
path
)
# track starts to track wcfs file corresponding to zf@at.
# see returned tFile for details.
def
track
(
t
,
zf
,
at
=
None
):
tf
=
tFile
(
t
,
zf
,
at
=
at
)
t
.
tracked
.
add
(
tf
)
return
tf
# tFile is testing environment for one bigfile on wcfs.
class
tFile
:
def
__init__
(
t
,
tdb
,
zf
,
at
=
None
):
assert
isinstance
(
zf
,
ZBigFile
)
t
.
tdb
=
tdb
t
.
f
=
tdb
.
open
(
zf
,
at
=
at
)
t
.
blksize
=
zf
.
blksize
def
close
(
t
):
t
.
f
.
close
()
"""
# readblk reads ZBigFile[blk] from wcfs.
# XXX not needed?
@func
...
...
@@ -212,9 +236,16 @@ class tDB:
data += chunk
n -= len(chunk)
return data
"""
# assertCache asserts state of OS file cache.
#
# incorev is [] of 1/0 representing whether block data is present or not.
def
assertCache
(
t
,
incorev
):
pass
# TODO
# assert
File asserts that wcfs file corresponding to zf
has data blocks as specified.
# assert
Data asserts that file
has data blocks as specified.
#
# Expected blocks may be given with size < zf.blksize. In such case they
# are implicitly appended with trailing zeros.
...
...
@@ -222,32 +253,33 @@ class tDB:
# 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
)
st
=
t
.
stat
(
zf
,
at
=
at
)
assert
st
.
st_size
==
len
(
blkv
)
*
zf
.
blksize
def
assertData
(
t
,
blkv
,
mtime
=
None
):
st
=
os
.
fstat
(
t
.
f
.
fileno
())
assert
st
.
st_size
==
len
(
blkv
)
*
t
.
blksize
if
mtime
is
not
None
:
assert
st
.
st_mtime
==
tidtime
(
mtime
)
data
=
t
.
read
(
zf
,
at
=
at
)
assert
len
(
data
)
==
len
(
blkv
)
*
zf
.
blksize
# XXX hack -> access mapped page
t
.
f
.
seek
(
0
)
data
=
t
.
f
.
read
()
assert
len
(
data
)
==
len
(
blkv
)
*
t
.
blksize
for
i
,
blk
in
enumerate
(
blkv
):
assert
len
(
blk
)
<=
zf
.
blksize
blk
+=
b'
\
0
'
*
(
zf
.
blksize
-
len
(
blk
))
# trailing zeros
assert
data
[
i
*
zf
.
blksize
:(
i
+
1
)
*
zf
.
blksize
]
==
blk
,
(
"#blk: %d"
%
i
)
assert
len
(
blk
)
<=
t
.
blksize
blk
+=
b'
\
0
'
*
(
t
.
blksize
-
len
(
blk
))
# trailing zeros
assert
data
[
i
*
t
.
blksize
:(
i
+
1
)
*
t
.
blksize
]
==
blk
,
(
"#blk: %d"
%
i
)
# XXX assertCache for read blocks to be 1
# XXX text ...
# XXX parametrize zblk0, zblk1 XXX or just rely on tox?
@
func
def
test_wcfs
():
t
=
tDB
()
defer
(
t
.
close
)
t
.
root
[
'!file'
]
=
nonfile
=
Persistent
()
t
.
root
[
'zfile'
]
=
f
=
ZBigFile
(
blksize
)
t
.
root
[
'zfile'
]
=
z
f
=
ZBigFile
(
blksize
)
tid1
=
t
.
commit
()
tid2
=
t
.
commit
()
...
...
@@ -259,32 +291,34 @@ def test_wcfs():
t
.
stat
(
nonfile
)
assert
exc
.
value
.
errno
==
EINVAL
f
=
t
.
track
(
zf
)
# file initially empty
_
=
t
.
stat
(
f
)
assert
_
.
st_size
==
0
assert
_
.
st_mtime
==
tidtime
(
tid1
)
f
.
assertCache
([])
f
.
assertData
([],
mtime
=
tid1
)
# commit data to f and make sure we can see it on wcfs
# commit data to
z
f and make sure we can see it on wcfs
# use !wcfs mode so that we prepare data independently of wcfs code paths.
hole
=
10
fh
=
f
.
fileh_open
(
_use_wcfs
=
False
)
vma
=
fh
.
mmap
(
hole
,
1
)
# 1 page at offset=10
zfh
=
z
f
.
fileh_open
(
_use_wcfs
=
False
)
vma
=
zfh
.
mmap
(
hole
,
1
)
# 1 page at offset=10
s
=
b"hello world"
memcpy
(
vma
,
s
)
t
.
commit
()
t
.
wcsync
()
# sync wcfs to ZODB
# XXX assert cache = ø
t
.
assertFile
(
f
,
[
b''
]
*
hole
+
[
s
],
mtime
=
t
.
head
)
f
.
assertCache
([
0
]
*
(
hole
+
1
))
# initially not cached
f
.
assertData
([
b''
]
*
hole
+
[
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
fh
=
f
.
fileh_open
(
_use_wcfs
=
False
)
vma1
=
fh
.
mmap
(
hole
,
1
)
vma2
=
fh
.
mmap
(
hole
+
1
,
1
)
zfh
=
z
f
.
fileh_open
(
_use_wcfs
=
False
)
vma1
=
z
fh
.
mmap
(
hole
,
1
)
vma2
=
z
fh
.
mmap
(
hole
+
1
,
1
)
s1
=
b"hello 123"
s2
=
b"alpha"
memcpy
(
vma1
,
s1
)
...
...
@@ -294,12 +328,13 @@ def test_wcfs():
t
.
wcsync
()
# f @head
# XXX assert cache
t
.
assertFile
(
f
,
[
b''
]
*
hole
+
[
s1
+
b'ld'
,
s2
],
mtime
=
t
.
head
)
f
.
assertCache
([
1
]
*
hole
+
[
0
,
0
])
f
.
assertData
(
[
b''
]
*
hole
+
[
s1
+
b'ld'
,
s2
],
mtime
=
t
.
head
)
# f @tcommit1
# XXX assert cache
t
.
assertFile
(
f
,
[
b''
]
*
hole
+
[
s
],
at
=
tcommit1
)
# XXX + mtime=tcommit1?
f1
=
t
.
track
(
zf
,
at
=
tcommit1
)
f1
.
assertCache
([
0
]
*
hole
+
[
1
])
f1
.
assertData
([
b''
]
*
hole
+
[
s
])
# XXX + mtime=tcommit1?
# TODO pagecache state after loading (via mincore)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment