Commit 6dba6409 authored by Levin Zimmermann's avatar Levin Zimmermann

client_test: Support test cluster /w >1 master

Now it's possible to run client tests against a NEO cluster which
has more than one master nodes. We need this adjustement in order
to test NEO/go client modification in order to support more than
one master node.
parent 5d93e434
...@@ -63,7 +63,7 @@ type NEOSrv interface { ...@@ -63,7 +63,7 @@ type NEOSrv interface {
type NEOSrvOptions struct { type NEOSrvOptions struct {
workdir string // location for database and log files workdir string // location for database and log files
name string // name of the cluster name string // name of the cluster
// nmaster nmaster int // how many masters our cluster has
// npartition // npartition
// nreplica // nreplica
...@@ -82,7 +82,7 @@ type NEOPySrv struct { ...@@ -82,7 +82,7 @@ type NEOPySrv struct {
done chan struct{} // ready after Wait completes done chan struct{} // ready after Wait completes
errExit error // error from Wait errExit error // error from Wait
masterAddr string // address of master in spawned cluster masterAddrSlice []string // addresses of master in spawned cluster
} }
func (_ *NEOPySrv) Bugs() []string { func (_ *NEOPySrv) Bugs() []string {
...@@ -114,6 +114,7 @@ func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) { ...@@ -114,6 +114,7 @@ func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
// TODO set $PYTHONPATH to top, so that `import neo` works without `pip install -e .` // TODO set $PYTHONPATH to top, so that `import neo` works without `pip install -e .`
n.pysrv = xexec.Command("./py/runneo.py", workdir, opt.name) n.pysrv = xexec.Command("./py/runneo.py", workdir, opt.name)
n.pysrv.Args = append(n.pysrv.Args, "master_count="+fmt.Sprintf("%v", opt.nmaster))
if opt.SSL { if opt.SSL {
n.pysrv.Args = append(n.pysrv.Args, "ca=" +opt.CA()) n.pysrv.Args = append(n.pysrv.Args, "ca=" +opt.CA())
n.pysrv.Args = append(n.pysrv.Args, "cert="+opt.Cert()) n.pysrv.Args = append(n.pysrv.Args, "cert="+opt.Cert())
...@@ -165,7 +166,7 @@ func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) { ...@@ -165,7 +166,7 @@ func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
n.masterAddr = string(masterAddr) n.masterAddrSlice = strings.Split(string(masterAddr), " ")
return n, nil return n, nil
} }
...@@ -175,7 +176,7 @@ func (n *NEOPySrv) clusterName() string { ...@@ -175,7 +176,7 @@ func (n *NEOPySrv) clusterName() string {
} }
func (n *NEOPySrv) URL() string { func (n *NEOPySrv) URL() string {
return fmt.Sprintf("%s%s/%s", n.opt.URLPrefix(), n.masterAddr, n.clusterName()) return fmt.Sprintf("%s%s/%s", n.opt.URLPrefix(), strings.Join(n.masterAddrSlice, ","), n.clusterName())
} }
func (n *NEOPySrv) LogTail() (string, error) { func (n *NEOPySrv) LogTail() (string, error) {
...@@ -290,7 +291,7 @@ func StartNEOGoSrv(opt NEOSrvOptions) (_ *NEOGoSrv, err error) { ...@@ -290,7 +291,7 @@ func StartNEOGoSrv(opt NEOSrvOptions) (_ *NEOGoSrv, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
n.S = NewStorage(opt.name, []string{n.masterAddr()}, net, n.Sback) n.S = NewStorage(opt.name, n.masterAddrSlice(), net, n.Sback)
serveWG.Go(func(ctx context.Context) error { serveWG.Go(func(ctx context.Context) error {
return n.S.Run(ctx, n.Sl) return n.S.Run(ctx, n.Sl)
}) })
...@@ -353,12 +354,12 @@ func (n *NEOGoSrv) Close() (err error) { ...@@ -353,12 +354,12 @@ func (n *NEOGoSrv) Close() (err error) {
return err return err
} }
func (n *NEOGoSrv) masterAddr() string { func (n *NEOGoSrv) masterAddrSlice() []string {
return n.Ml.Addr().String() return []string {n.Ml.Addr().String()}
} }
func (n *NEOGoSrv) URL() string { func (n *NEOGoSrv) URL() string {
return fmt.Sprintf("%s%s/%s", n.opt.URLPrefix(), n.masterAddr(), n.opt.name) return fmt.Sprintf("%s%s/%s", n.opt.URLPrefix(), strings.Join(n.masterAddrSlice(), ","), n.opt.name)
} }
...@@ -437,13 +438,15 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption ...@@ -437,13 +438,15 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
// TODO + all variants with nreplica=X, npartition=Y, nmaster=Z, ... ? // TODO + all variants with nreplica=X, npartition=Y, nmaster=Z, ... ?
for _, ssl := range []bool{false, true} { for _, ssl := range []bool{false, true} {
kind := "" kind := ""
if ssl { kind = "ssl" } else { kind = "!ssl" } if ssl { kind = "ssl" } else { kind = "!ssl" }
neoOpt := NEOSrvOptions{ neoOpt := NEOSrvOptions{
name: "1", name: "1",
SSL: ssl, SSL: ssl,
nmaster: 1,
} }
// startNEOpy starts NEO/py server with database in workdir/ // startNEOpy starts NEO/py server with database in workdir/
...@@ -468,7 +471,9 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption ...@@ -468,7 +471,9 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
} }
cmd.Args = append(cmd.Args, cmd.Args = append(cmd.Args,
opt.Preload, opt.Preload,
npy.masterAddr, // py internal representation of master_nodes is a
// string where each addr is separated by 1 space
strings.Join(npy.masterAddrSlice, " "),
) )
cmd.Stdin = nil cmd.Stdin = nil
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
......
...@@ -45,6 +45,9 @@ def main(): ...@@ -45,6 +45,9 @@ def main():
kw = {'clear_databases': False} # switch default not to clear data on startup kw = {'clear_databases': False} # switch default not to clear data on startup
for arg in sys.argv[3:]: for arg in sys.argv[3:]:
k, v = arg.split('=') k, v = arg.split('=')
# We need to cast specific argument to specific types
if k in ("master_count",):
v = int(v)
kw[k] = v kw[k] = v
......
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