Commit f96c8ccd authored by Kirill Smelkov's avatar Kirill Smelkov

fixup! client_test: Support test cluster /w >1 master

- show all options in error context and ran test kind

- skip nmaster > 1 for NEO/go as that is currently not implemented on NEO/go server

- use json for interacting with runneo.py, so that we can use
  whatever builtin type for any argument without hardcoding ad-hoc
  handling of specific arguments inside runneo.py.

- adjust comments + cosmetics
parent 3c37c0fc
......@@ -96,11 +96,11 @@ func (_ *NEOPySrv) BugEncFixed() (bool, proto.Encoding) {
// StartNEOPySrv starts NEO/py server specified by options.
func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
workdir := opt.workdir
defer xerr.Contextf(&err, "start neo/py %s/%s", workdir, opt.name)
defer xerr.Contextf(&err, "start neo/py %s", opt)
ctx, cancel := context.WithCancel(context.Background())
workdir := opt.workdir
readyf := workdir + "/ready"
err = os.Remove(readyf)
if os.IsNotExist(err) {
......@@ -113,12 +113,11 @@ func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
n := &NEOPySrv{opt: opt, cancel: cancel, done: make(chan struct{})}
// 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.Args = append(n.pysrv.Args, "master_count="+fmt.Sprintf("%v", opt.nmaster))
n.pysrv = xexec.Command("./py/runneo.py", workdir, opt.name, "master_count="+fmt.Sprintf("%d", opt.nmaster))
if opt.SSL {
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, "key=" +opt.Key())
n.pysrv.Args = append(n.pysrv.Args, fmt.Sprintf("ca=%q", opt.CA()))
n.pysrv.Args = append(n.pysrv.Args, fmt.Sprintf("cert=%q", opt.Cert()))
n.pysrv.Args = append(n.pysrv.Args, fmt.Sprintf("key=%q", opt.Key()))
}
// $TEMP -> workdir (else NEO/py creates another one for e.g. coverage)
n.pysrv.Env = append(os.Environ(), "TEMP="+workdir)
......@@ -161,12 +160,12 @@ func StartNEOPySrv(opt NEOSrvOptions) (_ *NEOPySrv, err error) {
time.Sleep(10*time.Millisecond)
}
// retrieve master address
masterAddr, err := ioutil.ReadFile(readyf)
// retrieve masters addresses
maddrv, err := ioutil.ReadFile(readyf)
if err != nil {
return nil, err
}
n.masterAddrSlice = strings.Split(string(masterAddr), " ")
n.masterAddrSlice = strings.Split(string(maddrv), " ")
return n, nil
}
......@@ -254,7 +253,10 @@ func (_ *NEOGoSrv) BugEncFixed() (bool, proto.Encoding) {
// 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)
defer xerr.Contextf(&err, "start neo/go %s", opt)
if opt.nmaster > 1 {
return nil, fmt.Errorf("TODO: nmaster > 1 not implemented")
}
ctx, cancel := context.WithCancel(context.Background())
serveWG := xsync.NewWorkGroup(ctx)
......@@ -367,6 +369,13 @@ func (n *NEOGoSrv) URL() string {
const npytests = "../../neo/tests/"
// String returns human-readble representation of server options.
func (opt NEOSrvOptions) String() string {
s := fmt.Sprintf("%s/%s M%d ", opt.workdir, opt.name, opt.nmaster)
if opt.SSL { s += "ssl" } else { s += "!ssl" }
return s
}
// CA/Cert/Key files to use if opt.SSL=y; empty if SSL=n.
func (opt NEOSrvOptions) CA() string {
if !opt.SSL { return "" }
......@@ -442,8 +451,8 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
for _, nmaster := range []int{1, 1} {
for _, ssl := range []bool{false, true} {
kind := ""
if ssl { kind = "ssl" } else { kind = "!ssl" }
kind := fmt.Sprintf("M%d/", nmaster)
if ssl { kind += "ssl" } else { kind += "!ssl" }
neoOpt := NEOSrvOptions{
name: "1",
......@@ -504,6 +513,9 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
// NEO/go
t.Run("go/"+kind, func(t *testing.T) {
t.Helper()
if neoOpt.nmaster > 1 {
t.Skip("nmaster > 1 is TODO for NEO/go server")
}
inWorkDir(t, func(workdir string) {
X := xtesting.FatalIf(t)
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2020-2021 Nexedi SA and Contributors.
# Copyright (C) 2020-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
......@@ -24,14 +24,14 @@ Usage: runneo.py <workdir> <cluster-name> [k1=v1] [k2=v2] ...
{k->v} dict is optional arguments for NEOCluster.
<workdir>/ready is created with address of master after spawned cluster becomes
<workdir>/ready is created with addresses of masters after spawned cluster becomes
operational.
"""
from neo.tests.functional import NEOCluster
from golang import func, defer
import sys, os
import sys, os, json
from time import sleep
from signal import signal, SIGTERM
......@@ -45,9 +45,7 @@ def main():
kw = {'clear_databases': False} # switch default not to clear data on startup
for arg in sys.argv[3:]:
k, v = arg.split('=')
# We need to cast specific argument to specific types
if k in ("master_count",):
v = int(v)
v = json.loads(v)
kw[k] = v
......@@ -82,7 +80,7 @@ def main():
# dump information about ready cluster into readyf
with open("%s.tmp" % readyf, "w") as f:
f.write(cluster.master_nodes) # XXX ' ' separated if multiple masters
f.write(cluster.master_nodes) # NOTE ' ' separated if multiple masters
os.rename("%s.tmp" % readyf, readyf) # atomic
def _():
......
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