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
3041fee6
Commit
3041fee6
authored
Jul 06, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
afe3cd61
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
3 deletions
+61
-3
go/zodb/storage/zeo/zeo_test.go
go/zodb/storage/zeo/zeo_test.go
+61
-3
No files found.
go/zodb/storage/zeo/zeo_test.go
View file @
3041fee6
...
...
@@ -21,6 +21,7 @@ package zeo
import
(
"context"
"fmt"
"io/ioutil"
"net/url"
"os"
...
...
@@ -34,6 +35,7 @@ import (
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet"
)
// ZEOPySrv represents running ZEO/py server.
...
...
@@ -47,14 +49,23 @@ type ZEOPySrv struct {
errExit
error
// error from Wait
}
type
ZEOPyOptions
struct
{
msgpack
bool
// whether to advertise msgpack
}
func
StartZEOPySrv
(
fs1path
string
)
(
_
*
ZEOPySrv
,
err
error
)
{
// StartZEOPySrv starts ZEO/py server for FileStorage database located at fs1path.
func
StartZEOPySrv
(
fs1path
string
,
opt
ZEOPyOptions
)
(
_
*
ZEOPySrv
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"startzeo %s"
,
fs1path
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
z
:=
&
ZEOPySrv
{
fs1path
:
fs1path
,
cancel
:
cancel
,
done
:
make
(
chan
struct
{})}
z
.
pysrv
=
exec
.
CommandContext
(
ctx
,
"python"
,
"-m"
,
"ZEO.runzeo"
,
"-f"
,
fs1path
,
"-a"
,
z
.
zaddr
())
msgpack
:=
""
if
opt
.
msgpack
{
msgpack
=
"y"
}
z
.
pysrv
.
Env
=
append
(
os
.
Environ
(),
"ZEO_MSGPACK="
+
msgpack
)
z
.
pysrv
.
Stdin
=
nil
z
.
pysrv
.
Stdout
=
os
.
Stdout
z
.
pysrv
.
Stderr
=
os
.
Stderr
...
...
@@ -118,6 +129,46 @@ func (z *ZEOPySrv) Close() (err error) {
// --------
// withZEOPySrv spawns new ZEO/py server and runs f in that environment.
func
withZEOPySrv
(
t
*
testing
.
T
,
opt
ZEOPyOptions
,
f
func
(
zpy
*
ZEOPySrv
))
{
X
:=
mkFatalIf
(
t
)
t
.
Helper
()
needZEOpy
(
t
)
work
:=
xtempdir
(
t
)
defer
os
.
RemoveAll
(
work
)
fs1path
:=
work
+
"/1.fs"
zpy
,
err
:=
StartZEOPySrv
(
fs1path
,
opt
);
X
(
err
)
defer
func
()
{
err
:=
zpy
.
Close
();
X
(
err
)
}()
f
(
zpy
)
}
func
TestHandshake
(
t
*
testing
.
T
)
{
X
:=
mkFatalIf
(
t
)
for
_
,
msgpack
:=
range
[]
bool
{
false
,
true
}
{
t
.
Run
(
fmt
.
Sprintf
(
"msgpack=%v"
,
msgpack
),
func
(
t
*
testing
.
T
)
{
withZEOPySrv
(
t
,
ZEOPyOptions
{
msgpack
:
msgpack
},
func
(
zpy
*
ZEOPySrv
)
{
ctx
:=
context
.
Background
()
net
:=
xnet
.
NetPlain
(
"unix"
)
zlink
,
err
:=
dialZLink
(
ctx
,
net
,
zpy
.
zaddr
());
X
(
err
)
defer
func
()
{
err
:=
zlink
.
Close
();
X
(
err
)
}()
ewant
:=
byte
(
'Z'
)
if
msgpack
{
ewant
=
byte
(
'M'
)
}
if
zlink
.
encoding
!=
ewant
{
t
.
Fatalf
(
"handshake: encoding=%c ; want %c"
,
zlink
.
encoding
,
ewant
)
}
})
})
}
}
func
TestLoad
(
t
*
testing
.
T
)
{
X
:=
exc
.
Raiseif
needZEOpy
(
t
)
...
...
@@ -132,7 +183,7 @@ func TestLoad(t *testing.T) {
txnvOk
,
err
:=
xtesting
.
LoadDB
(
fs1path
);
X
(
err
)
zpy
,
err
:=
StartZEOPySrv
(
fs1path
);
X
(
err
)
zpy
,
err
:=
StartZEOPySrv
(
fs1path
,
ZEOPyOptions
{}
);
X
(
err
)
defer
func
()
{
err
:=
zpy
.
Close
();
X
(
err
)
}()
...
...
@@ -153,7 +204,7 @@ func TestWatch(t *testing.T) {
defer
os
.
RemoveAll
(
work
)
fs1path
:=
work
+
"/1.fs"
zpy
,
err
:=
StartZEOPySrv
(
fs1path
);
X
(
err
)
zpy
,
err
:=
StartZEOPySrv
(
fs1path
,
ZEOPyOptions
{}
);
X
(
err
)
defer
func
()
{
err
:=
zpy
.
Close
();
X
(
err
)
}()
...
...
@@ -186,6 +237,13 @@ func xtempdir(t *testing.T) string {
return
tmpd
}
func
mkFatalIf
(
t
*
testing
.
T
)
func
(
error
)
{
return
func
(
err
error
)
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}
func
needZEOpy
(
t
*
testing
.
T
)
{
xtesting
.
NeedPy
(
t
,
"ZEO"
)
// XXX +msgpack?
...
...
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