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
4eb451a4
Commit
4eb451a4
authored
Jan 20, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5c8cfac1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
51 deletions
+57
-51
go/internal/xtesting/xtesting.go
go/internal/xtesting/xtesting.go
+48
-0
go/zodb/db_test.go
go/zodb/db_test.go
+3
-2
go/zodb/storage/fs1/filestorage_test.go
go/zodb/storage/fs1/filestorage_test.go
+6
-49
No files found.
go/internal/xtesting/xtesting.go
View file @
4eb451a4
...
...
@@ -21,9 +21,15 @@
package
xtesting
import
(
"bytes"
"fmt"
"os"
"os/exec"
"sync"
"testing"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb"
)
var
(
...
...
@@ -80,3 +86,45 @@ func NeedPy(t testing.TB, modules ...string) {
// we verified everything - now it is ok not to skip.
return
}
// ZObject represents object state to be committed.
type
ZObject
struct
{
Oid
zodb
.
Oid
Data
string
}
// ZPyCommit commits new transaction into database @ zurl with data specified by objv.
//
// The commit is performed via zodbtools/py.
func
ZPyCommit
(
zurl
string
,
at
zodb
.
Tid
,
objv
...
ZObject
)
(
_
zodb
.
Tid
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"%s: zcommit @%s"
,
zurl
,
at
)
// prepare text input for `zodb commit`
zin
:=
&
bytes
.
Buffer
{}
fmt
.
Fprintf
(
zin
,
"user %q
\n
"
,
"author"
)
fmt
.
Fprintf
(
zin
,
"description %q
\n
"
,
fmt
.
Sprintf
(
"test commit; at=%s"
,
at
))
fmt
.
Fprintf
(
zin
,
"extension %q
\n
"
,
""
)
for
_
,
obj
:=
range
objv
{
fmt
.
Fprintf
(
zin
,
"obj %s %d null:00
\n
"
,
obj
.
Oid
,
len
(
obj
.
Data
))
zin
.
WriteString
(
obj
.
Data
)
zin
.
WriteString
(
"
\n
"
)
}
zin
.
WriteString
(
"
\n
"
)
// run py `zodb commit`
cmd
:=
exec
.
Command
(
"python2"
,
"-m"
,
"zodbtools.zodb"
,
"commit"
,
zurl
,
at
.
String
())
cmd
.
Stdin
=
zin
cmd
.
Stderr
=
os
.
Stderr
out
,
err
:=
cmd
.
Output
()
if
err
!=
nil
{
return
zodb
.
InvalidTid
,
err
}
out
=
bytes
.
TrimSuffix
(
out
,
[]
byte
(
"
\n
"
))
tid
,
err
:=
zodb
.
ParseTid
(
string
(
out
))
if
err
!=
nil
{
return
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"committed, but invalid output: %s"
,
err
)
}
return
tid
,
nil
}
go/zodb/db_test.go
View file @
4eb451a4
// Copyright (C) 201
8
Nexedi SA and Contributors.
// Copyright (C) 201
9
Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
...
...
@@ -19,4 +19,5 @@
package
zodb
// TODO
func
TestDB
()
{
}
go/zodb/storage/fs1/filestorage_test.go
View file @
4eb451a4
...
...
@@ -20,13 +20,10 @@
package
fs1
import
(
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"reflect"
"testing"
...
...
@@ -34,7 +31,6 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/xerr"
)
// one database transaction record
...
...
@@ -362,54 +358,15 @@ func TestWatch(t *testing.T) {
workdir
:=
xworkdir
(
t
)
tfs
:=
workdir
+
"/t.fs"
// Object represents object state to be committed.
type
Object
struct
{
oid
zodb
.
Oid
data
string
}
// zcommit commits new transaction into tfs with data specified by objv.
zcommit
:=
func
(
at
zodb
.
Tid
,
objv
...
Object
)
(
_
zodb
.
Tid
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"zcommit @%s"
,
at
)
// prepare text input for `zodb commit`
zin
:=
&
bytes
.
Buffer
{}
fmt
.
Fprintf
(
zin
,
"user %q
\n
"
,
"author"
)
fmt
.
Fprintf
(
zin
,
"description %q
\n
"
,
fmt
.
Sprintf
(
"test commit; at=%s"
,
at
))
fmt
.
Fprintf
(
zin
,
"extension %q
\n
"
,
""
)
for
_
,
obj
:=
range
objv
{
fmt
.
Fprintf
(
zin
,
"obj %s %d null:00
\n
"
,
obj
.
oid
,
len
(
obj
.
data
))
zin
.
WriteString
(
obj
.
data
)
zin
.
WriteString
(
"
\n
"
)
}
zin
.
WriteString
(
"
\n
"
)
// run py `zodb commit`
cmd
:=
exec
.
Command
(
"python2"
,
"-m"
,
"zodbtools.zodb"
,
"commit"
,
tfs
,
at
.
String
())
cmd
.
Stdin
=
zin
cmd
.
Stderr
=
os
.
Stderr
out
,
err
:=
cmd
.
Output
()
if
err
!=
nil
{
return
zodb
.
InvalidTid
,
err
}
out
=
bytes
.
TrimSuffix
(
out
,
[]
byte
(
"
\n
"
))
tid
,
err
:=
zodb
.
ParseTid
(
string
(
out
))
if
err
!=
nil
{
return
zodb
.
InvalidTid
,
fmt
.
Errorf
(
"committed, but invalid output: %s"
,
err
)
}
return
tid
,
nil
}
xcommit
:=
func
(
at
zodb
.
Tid
,
objv
...
Object
)
zodb
.
Tid
{
// xcommit commits new transaction into tfs with data specified by objv.
xcommit
:=
func
(
at
zodb
.
Tid
,
objv
...
xtesting
.
ZObject
)
zodb
.
Tid
{
t
.
Helper
()
tid
,
err
:=
zcommit
(
at
,
objv
...
);
X
(
err
)
tid
,
err
:=
xtesting
.
ZPyCommit
(
tfs
,
at
,
objv
...
);
X
(
err
)
return
tid
}
// force tfs creation & open tfs at go side
at
:=
xcommit
(
0
,
Object
{
0
,
"data0"
})
at
:=
xcommit
(
0
,
xtesting
.
Z
Object
{
0
,
"data0"
})
watchq
:=
make
(
chan
zodb
.
CommitEvent
)
fs
:=
xfsopenopt
(
t
,
tfs
,
&
zodb
.
DriverOptions
{
ReadOnly
:
true
,
Watchq
:
watchq
})
...
...
@@ -450,8 +407,8 @@ func TestWatch(t *testing.T) {
data0
:=
fmt
.
Sprintf
(
"data0.%d"
,
i
)
datai
:=
fmt
.
Sprintf
(
"data%d"
,
i
)
at
=
xcommit
(
at
,
Object
{
0
,
data0
},
Object
{
i
,
datai
})
xtesting
.
Z
Object
{
0
,
data0
},
xtesting
.
Z
Object
{
i
,
datai
})
// TODO also test for watcher errors
e
:=
<-
watchq
...
...
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