Commit a87adb49 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c744c005
...@@ -21,21 +21,24 @@ package neo ...@@ -21,21 +21,24 @@ package neo
import ( import (
"context" "context"
"fmt"
"io/ioutil" "io/ioutil"
"net/url"
"os" "os"
"os/exec" "os/exec"
"testing" "testing"
"time" "time"
"lab.nexedi.com/kirr/neo/go/internal/xtesting" "lab.nexedi.com/kirr/neo/go/internal/xtesting"
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
) )
// NEOSrv represents running NEO server. // NEOSrv represents running NEO server.
type NEOSrv interface { type NEOSrv interface {
MasterAddr() string // address of the master ClusterName() string // name of the cluster
// XXX +ClusterName MasterAddr() string // address of the master
} }
// NEOPySrv represents running NEO/py server. // NEOPySrv represents running NEO/py server.
...@@ -130,6 +133,10 @@ func StartNEOPySrv(workdir string, opt NEOPyOptions) (_ *NEOPySrv, err error) { ...@@ -130,6 +133,10 @@ func StartNEOPySrv(workdir string, opt NEOPyOptions) (_ *NEOPySrv, err error) {
return n, nil return n, nil
} }
func (n *NEOPySrv) ClusterName() string {
return "xxx" // FIXME stub
}
func (n *NEOPySrv) MasterAddr() string { func (n *NEOPySrv) MasterAddr() string {
return n.masterAddr return n.masterAddr
} }
...@@ -148,10 +155,24 @@ func (n *NEOPySrv) Close() (err error) { ...@@ -148,10 +155,24 @@ func (n *NEOPySrv) Close() (err error) {
// ---------------- // ----------------
// tOptions represents options for testing.
// XXX dup in ZEO
type tOptions struct {
Preload string // preload database with data from this location
}
// withNEOSrv tests f with all kind of NEO servers. // withNEOSrv tests f with all kind of NEO servers.
func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv)) { // XXX +optv ? func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOptions) {
t.Helper() t.Helper()
opt := tOptions{}
if len(optv) > 1 {
panic("multiple tOptions not allowed")
}
if len(optv) == 1 {
opt = optv[0]
}
// inWorkDir runs f under dedicated work directory. // inWorkDir runs f under dedicated work directory.
inWorkDir := func(t *testing.T, f func(workdir string)) { inWorkDir := func(t *testing.T, f func(workdir string)) {
t.Helper() t.Helper()
...@@ -159,6 +180,10 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv)) { // XXX +optv ...@@ -159,6 +180,10 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv)) { // XXX +optv
work, err := ioutil.TempDir("", "neo"); X(err) work, err := ioutil.TempDir("", "neo"); X(err)
defer os.RemoveAll(work) defer os.RemoveAll(work)
if opt.Preload != "" {
panic("TODO: preload")
}
f(work) f(work)
} }
...@@ -184,10 +209,40 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv)) { // XXX +optv ...@@ -184,10 +209,40 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv)) { // XXX +optv
// TODO NEO/go // TODO NEO/go
} }
// XXX withNeo // withNEO tests f on all kinds of NEO servers connected to by NEO client.
func withNEO(t *testing.T, f func(t *testing.T, nsrv NEOSrv, ndrv *Client), optv ...tOptions) {
t.Helper()
withNEOSrv(t, func(t *testing.T, nsrv NEOSrv) {
t.Helper()
X := xtesting.FatalIf(t)
ndrv, _, err := neoOpen(fmt.Sprintf("%s@%s", nsrv.ClusterName(), nsrv.MasterAddr()),
&zodb.DriverOptions{ReadOnly: true}); X(err)
defer func() {
err := ndrv.Close(); X(err)
}()
f(t, nsrv, ndrv)
}, optv...)
}
func TestEmptyDB(t *testing.T) { func TestEmptyDB(t *testing.T) {
withNEO(t, func(t *testing.T, nsrv NEOSrv, n *Client) { withNEO(t, func(t *testing.T, nsrv NEOSrv, n *Client) {
xtesting.DrvTestEmptyDB(t, n) xtesting.DrvTestEmptyDB(t, n)
}) })
} }
func neoOpen(zurl string, opt *zodb.DriverOptions) (_ *Client, at0 zodb.Tid, err error) {
defer xerr.Contextf(&err, "openneo %s", zurl)
u, err := url.Parse(zurl)
if err != nil {
return nil, 0, err
}
n, at0, err := openClientByURL(context.Background(), u, opt)
if err != nil {
return nil, 0, err
}
return n.(*Client), at0, nil
}
...@@ -154,6 +154,7 @@ func (z *ZEOPySrv) Encoding() encoding { ...@@ -154,6 +154,7 @@ func (z *ZEOPySrv) Encoding() encoding {
// ---------------- // ----------------
// tOptions represents options for testing. // tOptions represents options for testing.
// XXX dup in NEO
type tOptions struct { type tOptions struct {
Preload string // preload database with data from this location Preload string // preload database with data from this location
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment