Commit 60a44061 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a2f192cb
......@@ -46,14 +46,26 @@ type NEOSrv interface {
Bugs() []string // list of known server bugs
}
// NEOSrvOptions represents options for a NEO server.
type NEOSrvOptions struct {
workdir string // location for database and log files
name string // name of the cluster
// nmaster
// npartition
// nreplica
SSL bool // whether to use SSL for node-node exchange
}
// ---- NEO/py ----
// NEOPySrv represents running NEO/py server.
//
// Create it with StartNEOPySrv(XXX).
// Create it with StartNEOPySrv.
type NEOPySrv struct {
pysrv *xexec.Cmd // spawned `runneo.py`
workdir string // location for database and log files
clusterName string // name of the cluster
opt NEOPyOptions // options for spawned server
opt NEOSrvOptions // options for spawned server
cancel func() // to stop pysrv
done chan struct{} // ready after Wait completes
errExit error // error from Wait
......@@ -67,25 +79,14 @@ type NEOPySrv struct {
}
func (_ *NEOPySrv) Bugs() []string {
return []string{
// XXX
}
return []string{}
}
type NEOPyOptions struct {
// nmaster
// npartition
// nreplica
// name
SSL bool // whether to use SSL for node-node exchange
}
// StartNEOPySrv starts NEO/py server for clusterName NEO database located in workdir/.
// StartNEOPySrv starts NEO/py server specified by options.
// XXX dup wrt zeo?
func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv, err error) {
defer xerr.Contextf(&err, "startneo %s/%s", workdir, clusterName)
func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
workdir := opt.workdir
defer xerr.Contextf(&err, "start neo/py %s/%s", workdir, opt.name)
ctx, cancel := context.WithCancel(context.Background())
......@@ -98,7 +99,7 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv,
return nil, err
}
n := &NEOPySrv{workdir: workdir, clusterName: clusterName, cancel: cancel, done: make(chan struct{})}
n := &NEOPySrv{opt: opt, cancel: cancel, done: make(chan struct{})}
if opt.SSL {
npytests := "../../neo/tests/"
n.CA = npytests + "ca.crt"
......@@ -107,13 +108,12 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv,
}
// XXX $PYTHONPATH to top, so that `import neo` works?
n.pysrv = xexec.Command("./py/runneo.py", workdir, clusterName)
n.pysrv = xexec.Command("./py/runneo.py", workdir, opt.name)
if opt.SSL {
n.pysrv.Args = append(n.pysrv.Args, "ca=" +n.CA)
n.pysrv.Args = append(n.pysrv.Args, "cert="+n.Cert)
n.pysrv.Args = append(n.pysrv.Args, "key=" +n.Key)
}
n.opt = opt
// $TEMP -> workdir (else NEO/py creates another one for e.g. coverage)
n.pysrv.Env = append(os.Environ(), "TEMP="+workdir)
n.pysrv.Stdin = nil
......@@ -166,7 +166,7 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv,
}
func (n *NEOPySrv) ClusterName() string {
return n.clusterName
return n.opt.name
}
func (n *NEOPySrv) MasterAddr() string {
......@@ -190,7 +190,7 @@ func (n *NEOPySrv) ZUrl() string {
}
func (n *NEOPySrv) Close() (err error) {
defer xerr.Contextf(&err, "stopneo %s", n.workdir)
defer xerr.Contextf(&err, "stop neo/py %s", n.opt.workdir)
n.cancel()
<-n.done
......@@ -201,6 +201,37 @@ func (n *NEOPySrv) Close() (err error) {
return err
}
// ---- NEO/go ----
// NEOGoSrv represents running NEO/go server.
//
// Create it with StartNEOGoSrv.
type NEOGoSrv struct {
// XXX
opt NEOSrvOptions // server options
}
func (_ *NEOGoSrv) Bugs() []string {
return []string{"nocommit"}
}
// StartNEOGoSrv starts NEO/go server specified by options.
func StartNEOGoSrv(opt NEOSrvOptions) (_ *NEOGoSrv, err error) {
defer xerr.Contextf(&err, "start neo/go %s/%s", opt.workdir, opt.name)
return nil, fmt.Errorf("TODO")
}
func (n *NEOGoSrv) Close() (err error) {
defer xerr.Contextf(&err, "stop neo/go %s", n.opt.workdir)
panic("TODO")
}
func (n *NEOGoSrv) ZUrl() string {
panic("TODO")
}
// ----------------
// tOptions represents options for testing.
......@@ -237,6 +268,43 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
kind := ""
if ssl { kind = "ssl" } else { kind = "!ssl" }
neoOpt := NEOSrvOptions{
name: "1",
SSL: ssl,
}
// startNEOpy starts NEO/py server with database in workdir/
// and preloads it with data according to opt.Preload.
startNEOpy := func(t *testing.T, workdir string) *NEOPySrv {
X := xtesting.FatalIf(t)
neoOpt := neoOpt
neoOpt.workdir = workdir
npy, err := StartNEOPySrv(neoOpt); X(err)
if opt.Preload != "" {
cmd := exec.Command("python", "-c",
"from neo.scripts.neomigrate import main; main()",
"-q",
"-c", npy.ClusterName(),
)
if ssl {
cmd.Args = append(cmd.Args, "--ca", npy.CA)
cmd.Args = append(cmd.Args, "--cert", npy.Cert)
cmd.Args = append(cmd.Args, "--key", npy.Key)
}
cmd.Args = append(cmd.Args,
opt.Preload,
npy.MasterAddr(),
)
cmd.Stdin = nil
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run(); X(err)
}
return npy
}
// NEO/py
t.Run("py/"+kind, func(t *testing.T) {
t.Helper()
......@@ -244,40 +312,39 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
inWorkDir(t, func(workdir string) {
X := xtesting.FatalIf(t)
npy, err := StartNEOPySrv(workdir, "1", NEOPyOptions{
SSL: ssl,
}); X(err)
npy := startNEOpy(t, workdir)
defer func() {
err := npy.Close(); X(err)
}()
if opt.Preload != "" {
cmd := exec.Command("python", "-c",
"from neo.scripts.neomigrate import main; main()",
"-q",
"-c", npy.ClusterName(),
)
if ssl {
cmd.Args = append(cmd.Args, "--ca", npy.CA)
cmd.Args = append(cmd.Args, "--cert", npy.Cert)
cmd.Args = append(cmd.Args, "--key", npy.Key)
}
cmd.Args = append(cmd.Args,
opt.Preload,
npy.MasterAddr(),
)
cmd.Stdin = nil
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run(); X(err)
}
f(t, npy)
})
})
// NEO/go
t.Run("go/"+kind, func(t *testing.T) {
t.Helper()
inWorkDir(t, func(workdir string) {
X := xtesting.FatalIf(t)
neoOpt := neoOpt
neoOpt.workdir = workdir
// TODO NEO/go
// start NEO/py first. We need it to create the
// database and to preload it, because NEO/go
// does not support commit.
npy := startNEOpy(t, workdir)
err := npy.Close(); X(err)
// now, as the database is created and preloaded, start NEO/go
ngo, err := StartNEOGoSrv(neoOpt); X(err)
defer func() {
err := ngo.Close(); X(err)
}()
f(t, ngo)
})
})
}
}
......
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