Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
a5d7b5a4
Commit
a5d7b5a4
authored
Jul 05, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
4852419c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
127 additions
and
2 deletions
+127
-2
go/internal/xtesting/xtesting.go
go/internal/xtesting/xtesting.go
+101
-2
go/zodb/storage/fs1/filestorage_test.go
go/zodb/storage/fs1/filestorage_test.go
+26
-0
No files found.
go/internal/xtesting/xtesting.go
View file @
a5d7b5a4
...
...
@@ -137,8 +137,107 @@ func ZPyCommitRaw(zurl string, at zodb.Tid, objv ...ZRawObject) (_ zodb.Tid, err
// ---- tests for storage drivers ----
// state of an object in the database for some particular revision
type
objState
struct
{
tid
zodb
.
Tid
data
[]
byte
// nil if obj was deleted
}
// Txn represents one transaction.
type
Txn
struct
{
Header
*
zodb
.
TxnInfo
Data
[]
*
zodb
.
DataInfo
}
// checkLoad verifies that zdrv.Load(xid) returns expected result
func
checkLoad
(
t
*
testing
.
T
,
zdrv
zodb
.
IStorageDriver
,
xid
zodb
.
Xid
,
expect
objState
)
{
t
.
Helper
()
buf
,
tid
,
err
:=
zdrv
.
Load
(
context
.
Background
(),
xid
)
// deleted obj - it should load with "no data"
if
expect
.
data
==
nil
{
errOk
:=
&
zodb
.
OpError
{
URL
:
zdrv
.
URL
(),
Op
:
"load"
,
Args
:
xid
,
Err
:
&
zodb
.
NoDataError
{
Oid
:
xid
.
Oid
,
DeletedAt
:
expect
.
tid
},
}
if
!
reflect
.
DeepEqual
(
err
,
errOk
)
{
t
.
Errorf
(
"load %v: returned err unexpected: %v ; want: %v"
,
xid
,
err
,
errOk
)
}
if
tid
!=
0
{
t
.
Errorf
(
"load %v: returned tid unexpected: %v ; want: %v"
,
xid
,
tid
,
expect
.
tid
)
}
if
buf
!=
nil
{
t
.
Errorf
(
"load %v: returned buf != nil"
,
xid
)
}
// regular load
}
else
{
if
err
!=
nil
{
t
.
Errorf
(
"load %v: returned err unexpected: %v ; want: nil"
,
xid
,
err
)
}
if
tid
!=
expect
.
tid
{
t
.
Errorf
(
"load %v: returned tid unexpected: %v ; want: %v"
,
xid
,
tid
,
expect
.
tid
)
}
switch
{
case
buf
==
nil
:
t
.
Errorf
(
"load %v: returned buf = nil"
,
xid
)
case
!
reflect
.
DeepEqual
(
buf
.
Data
,
expect
.
data
)
:
// NOTE reflect to catch nil != ""
t
.
Errorf
(
"load %v: different data:
\n
have: %q
\n
want: %q"
,
xid
,
buf
.
Data
,
expect
.
data
)
}
}
}
// DrvTestLoad verifies that zdrv implements Load correctly.
//
// txnvOk is what data to expect to be in the database.
func
DrvTestLoad
(
t
*
testing
.
T
,
zdrv
zodb
.
IStorageDriver
,
txnvOk
[]
Txn
)
{
t
.
Helper
()
// current knowledge of what was "before" for an oid as we scan over
// data base entries
before
:=
map
[
zodb
.
Oid
]
objState
{}
for
_
,
txn
:=
range
txnvOk
{
for
_
,
obj
:=
range
txn
.
Data
{
txh
:=
txn
.
Header
// XXX assert obj.Tid == txn.Tid
// XXX check Load finds data at correct .Pos / etc ?
// ~ loadSerial
xid
:=
zodb
.
Xid
{
txh
.
Tid
,
obj
.
Oid
}
checkLoad
(
t
,
zdrv
,
xid
,
objState
{
txh
.
Tid
,
obj
.
Data
})
// ~ loadBefore
xid
=
zodb
.
Xid
{
txh
.
Tid
-
1
,
obj
.
Oid
}
expect
,
ok
:=
before
[
obj
.
Oid
]
if
ok
{
checkLoad
(
t
,
zdrv
,
xid
,
expect
)
}
before
[
obj
.
Oid
]
=
objState
{
txh
.
Tid
,
obj
.
Data
}
}
}
// load at ∞ with TidMax
// XXX should we get "no such transaction" with at > head? - yes
for
oid
,
expect
:=
range
before
{
xid
:=
zodb
.
Xid
{
zodb
.
TidMax
,
oid
}
checkLoad
(
t
,
zdrv
,
xid
,
expect
)
}
}
// DrvTestWatch verifies that storage driver watcher can observe commits done from outside.
func
DrvTestWatch
(
t
*
testing
.
T
,
zurl
string
,
drvOpen
zodb
.
DriverOpener
)
{
func
DrvTestWatch
(
t
*
testing
.
T
,
zurl
string
,
z
drvOpen
zodb
.
DriverOpener
)
{
t
.
Helper
()
X
:=
func
(
err
error
)
{
if
err
!=
nil
{
...
...
@@ -162,7 +261,7 @@ func DrvTestWatch(t *testing.T, zurl string, drvOpen zodb.DriverOpener) {
ctx
:=
context
.
Background
()
watchq
:=
make
(
chan
zodb
.
Event
)
zdrv
,
at0
,
err
:=
drvOpen
(
ctx
,
u
,
&
zodb
.
DriverOptions
{
ReadOnly
:
true
,
Watchq
:
watchq
})
zdrv
,
at0
,
err
:=
z
drvOpen
(
ctx
,
u
,
&
zodb
.
DriverOptions
{
ReadOnly
:
true
,
Watchq
:
watchq
})
if
at0
!=
at
{
t
.
Fatalf
(
"opened @ %s ; want %s"
,
at0
,
at
)
}
...
...
go/zodb/storage/fs1/filestorage_test.go
View file @
a5d7b5a4
...
...
@@ -58,6 +58,7 @@ func (txe *txnEntry) Data() []byte {
return
data
}
/*
// state of an object in the database for some particular revision
type objState struct {
tid zodb.Tid
...
...
@@ -109,6 +110,7 @@ func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect objState) {
}
}
}
*/
func
xfsopen
(
t
testing
.
TB
,
path
string
)
(
*
FileStorage
,
zodb
.
Tid
)
{
t
.
Helper
()
...
...
@@ -128,6 +130,27 @@ func TestLoad(t *testing.T) {
fs
,
_
:=
xfsopen
(
t
,
"testdata/1.fs"
)
defer
exc
.
XRun
(
fs
.
Close
)
txnv
:=
[]
xtesting
.
Txn
{}
for
_
,
dbe
:=
range
_1fs_dbEntryv
{
txn
:=
xtesting
.
Txn
{
Header
:
&
zodb
.
TxnInfo
{
Tid
:
dbe
.
Header
.
Tid
,
}}
for
_
,
txe
:=
range
dbe
.
Entryv
{
data
:=
&
zodb
.
DataInfo
{
Oid
:
txe
.
Header
.
Oid
,
Tid
:
txn
.
Header
.
Tid
,
Data
:
txe
.
Data
(),
DataTidHint
:
txe
.
DataTidHint
,
}
txn
.
Data
=
append
(
txn
.
Data
,
data
)
}
txnv
=
append
(
txnv
,
txn
)
}
xtesting
.
DrvTestLoad
(
t
,
fs
,
txnv
)
/*
// current knowledge of what was "before" for an oid as we scan over
// data base entries
before := map[zodb.Oid]objState{}
...
...
@@ -160,6 +183,7 @@ func TestLoad(t *testing.T) {
xid := zodb.Xid{zodb.TidMax, oid}
checkLoad(t, fs, xid, expect)
}
*/
}
// iterate tidMin..tidMax and expect db entries in expectv
...
...
@@ -273,6 +297,7 @@ func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv
}
}
// TODO -> xtesting
func
TestIterate
(
t
*
testing
.
T
)
{
fs
,
_
:=
xfsopen
(
t
,
"testdata/1.fs"
)
defer
exc
.
XRun
(
fs
.
Close
)
...
...
@@ -309,6 +334,7 @@ func TestIterate(t *testing.T) {
testIterate
(
t
,
fs
,
0
,
zodb
.
TidMax
,
_1fs_dbEntryv
[
:
])
}
// TODO -> xtesting
func
BenchmarkIterate
(
b
*
testing
.
B
)
{
fs
,
_
:=
xfsopen
(
b
,
"testdata/1.fs"
)
defer
exc
.
XRun
(
fs
.
Close
)
...
...
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