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

.

parent a2f192cb
...@@ -46,14 +46,26 @@ type NEOSrv interface { ...@@ -46,14 +46,26 @@ type NEOSrv interface {
Bugs() []string // list of known server bugs 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. // NEOPySrv represents running NEO/py server.
// //
// Create it with StartNEOPySrv(XXX). // Create it with StartNEOPySrv.
type NEOPySrv struct { type NEOPySrv struct {
pysrv *xexec.Cmd // spawned `runneo.py` pysrv *xexec.Cmd // spawned `runneo.py`
workdir string // location for database and log files opt NEOSrvOptions // options for spawned server
clusterName string // name of the cluster
opt NEOPyOptions // options for spawned server
cancel func() // to stop pysrv cancel func() // to stop pysrv
done chan struct{} // ready after Wait completes done chan struct{} // ready after Wait completes
errExit error // error from Wait errExit error // error from Wait
...@@ -67,25 +79,14 @@ type NEOPySrv struct { ...@@ -67,25 +79,14 @@ type NEOPySrv struct {
} }
func (_ *NEOPySrv) Bugs() []string { func (_ *NEOPySrv) Bugs() []string {
return []string{ return []string{}
// XXX
}
}
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? // XXX dup wrt zeo?
func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv, err error) { func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
defer xerr.Contextf(&err, "startneo %s/%s", workdir, clusterName) workdir := opt.workdir
defer xerr.Contextf(&err, "start neo/py %s/%s", workdir, opt.name)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
...@@ -98,7 +99,7 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv, ...@@ -98,7 +99,7 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv,
return nil, err 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 { if opt.SSL {
npytests := "../../neo/tests/" npytests := "../../neo/tests/"
n.CA = npytests + "ca.crt" n.CA = npytests + "ca.crt"
...@@ -107,13 +108,12 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv, ...@@ -107,13 +108,12 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv,
} }
// XXX $PYTHONPATH to top, so that `import neo` works? // 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 { if opt.SSL {
n.pysrv.Args = append(n.pysrv.Args, "ca=" +n.CA) 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, "cert="+n.Cert)
n.pysrv.Args = append(n.pysrv.Args, "key=" +n.Key) 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) // $TEMP -> workdir (else NEO/py creates another one for e.g. coverage)
n.pysrv.Env = append(os.Environ(), "TEMP="+workdir) n.pysrv.Env = append(os.Environ(), "TEMP="+workdir)
n.pysrv.Stdin = nil n.pysrv.Stdin = nil
...@@ -166,7 +166,7 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv, ...@@ -166,7 +166,7 @@ func StartNEOPySrv(workdir, clusterName string, opt NEOPyOptions) (_ *NEOPySrv,
} }
func (n *NEOPySrv) ClusterName() string { func (n *NEOPySrv) ClusterName() string {
return n.clusterName return n.opt.name
} }
func (n *NEOPySrv) MasterAddr() string { func (n *NEOPySrv) MasterAddr() string {
...@@ -190,7 +190,7 @@ func (n *NEOPySrv) ZUrl() string { ...@@ -190,7 +190,7 @@ func (n *NEOPySrv) ZUrl() string {
} }
func (n *NEOPySrv) Close() (err error) { 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.cancel()
<-n.done <-n.done
...@@ -201,6 +201,37 @@ func (n *NEOPySrv) Close() (err error) { ...@@ -201,6 +201,37 @@ func (n *NEOPySrv) Close() (err error) {
return err 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. // tOptions represents options for testing.
...@@ -237,20 +268,20 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption ...@@ -237,20 +268,20 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
kind := "" kind := ""
if ssl { kind = "ssl" } else { kind = "!ssl" } if ssl { kind = "ssl" } else { kind = "!ssl" }
// NEO/py neoOpt := NEOSrvOptions{
t.Run("py/"+kind, func(t *testing.T) { name: "1",
t.Helper() SSL: ssl,
// XXX needpy }
inWorkDir(t, func(workdir string) {
// 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) X := xtesting.FatalIf(t)
npy, err := StartNEOPySrv(workdir, "1", NEOPyOptions{ neoOpt := neoOpt
SSL: ssl, neoOpt.workdir = workdir
}); X(err)
defer func() {
err := npy.Close(); X(err)
}()
npy, err := StartNEOPySrv(neoOpt); X(err)
if opt.Preload != "" { if opt.Preload != "" {
cmd := exec.Command("python", "-c", cmd := exec.Command("python", "-c",
"from neo.scripts.neomigrate import main; main()", "from neo.scripts.neomigrate import main; main()",
...@@ -271,13 +302,49 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption ...@@ -271,13 +302,49 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
err := cmd.Run(); X(err) err := cmd.Run(); X(err)
} }
return npy
}
// NEO/py
t.Run("py/"+kind, func(t *testing.T) {
t.Helper()
// XXX needpy
inWorkDir(t, func(workdir string) {
X := xtesting.FatalIf(t)
npy := startNEOpy(t, workdir)
defer func() {
err := npy.Close(); X(err)
}()
f(t, npy) f(t, npy)
}) })
}) })
// NEO/go
t.Run("go/"+kind, func(t *testing.T) {
t.Helper()
inWorkDir(t, func(workdir string) {
X := xtesting.FatalIf(t)
// TODO NEO/go neoOpt := neoOpt
neoOpt.workdir = workdir
// 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