Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
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
Hide 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
...
@@ -21,6 +21,7 @@ package zeo
import
(
import
(
"context"
"context"
"fmt"
"io/ioutil"
"io/ioutil"
"net/url"
"net/url"
"os"
"os"
...
@@ -34,6 +35,7 @@ import (
...
@@ -34,6 +35,7 @@ import (
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet"
)
)
// ZEOPySrv represents running ZEO/py server.
// ZEOPySrv represents running ZEO/py server.
...
@@ -47,14 +49,23 @@ type ZEOPySrv struct {
...
@@ -47,14 +49,23 @@ type ZEOPySrv struct {
errExit
error
// error from Wait
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
)
defer
xerr
.
Contextf
(
&
err
,
"startzeo %s"
,
fs1path
)
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
z
:=
&
ZEOPySrv
{
fs1path
:
fs1path
,
cancel
:
cancel
,
done
:
make
(
chan
struct
{})}
z
:=
&
ZEOPySrv
{
fs1path
:
fs1path
,
cancel
:
cancel
,
done
:
make
(
chan
struct
{})}
z
.
pysrv
=
exec
.
CommandContext
(
ctx
,
"python"
,
"-m"
,
"ZEO.runzeo"
,
"-f"
,
fs1path
,
"-a"
,
z
.
zaddr
())
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
.
Stdin
=
nil
z
.
pysrv
.
Stdout
=
os
.
Stdout
z
.
pysrv
.
Stdout
=
os
.
Stdout
z
.
pysrv
.
Stderr
=
os
.
Stderr
z
.
pysrv
.
Stderr
=
os
.
Stderr
...
@@ -118,6 +129,46 @@ func (z *ZEOPySrv) Close() (err error) {
...
@@ -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
)
{
func
TestLoad
(
t
*
testing
.
T
)
{
X
:=
exc
.
Raiseif
X
:=
exc
.
Raiseif
needZEOpy
(
t
)
needZEOpy
(
t
)
...
@@ -132,7 +183,7 @@ func TestLoad(t *testing.T) {
...
@@ -132,7 +183,7 @@ func TestLoad(t *testing.T) {
txnvOk
,
err
:=
xtesting
.
LoadDB
(
fs1path
);
X
(
err
)
txnvOk
,
err
:=
xtesting
.
LoadDB
(
fs1path
);
X
(
err
)
zpy
,
err
:=
StartZEOPySrv
(
fs1path
);
X
(
err
)
zpy
,
err
:=
StartZEOPySrv
(
fs1path
,
ZEOPyOptions
{}
);
X
(
err
)
defer
func
()
{
defer
func
()
{
err
:=
zpy
.
Close
();
X
(
err
)
err
:=
zpy
.
Close
();
X
(
err
)
}()
}()
...
@@ -153,7 +204,7 @@ func TestWatch(t *testing.T) {
...
@@ -153,7 +204,7 @@ func TestWatch(t *testing.T) {
defer
os
.
RemoveAll
(
work
)
defer
os
.
RemoveAll
(
work
)
fs1path
:=
work
+
"/1.fs"
fs1path
:=
work
+
"/1.fs"
zpy
,
err
:=
StartZEOPySrv
(
fs1path
);
X
(
err
)
zpy
,
err
:=
StartZEOPySrv
(
fs1path
,
ZEOPyOptions
{}
);
X
(
err
)
defer
func
()
{
defer
func
()
{
err
:=
zpy
.
Close
();
X
(
err
)
err
:=
zpy
.
Close
();
X
(
err
)
}()
}()
...
@@ -186,6 +237,13 @@ func xtempdir(t *testing.T) string {
...
@@ -186,6 +237,13 @@ func xtempdir(t *testing.T) string {
return
tmpd
return
tmpd
}
}
func
mkFatalIf
(
t
*
testing
.
T
)
func
(
error
)
{
return
func
(
err
error
)
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}
func
needZEOpy
(
t
*
testing
.
T
)
{
func
needZEOpy
(
t
*
testing
.
T
)
{
xtesting
.
NeedPy
(
t
,
"ZEO"
)
// XXX +msgpack?
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