Commit b2929804 authored by Levin Zimmermann's avatar Levin Zimmermann

client_test: Add nmaster={1,2} to test matrix

Tests should work with both one master or more than one masters.
parent 6dba6409
......@@ -436,105 +436,108 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
f(work)
}
// TODO + all variants with nreplica=X, npartition=Y, nmaster=Z, ... ?
// TODO + all variants with nreplica=X, npartition=Y, ... ?
for _, ssl := range []bool{false, true} {
kind := ""
if ssl { kind = "ssl" } else { kind = "!ssl" }
for _, nmaster := range []int{1, 1} {
neoOpt := NEOSrvOptions{
name: "1",
SSL: ssl,
nmaster: 1,
}
for _, ssl := range []bool{false, true} {
kind := ""
if ssl { kind = "ssl" } else { kind = "!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, opt tOptions) *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", neoOpt.CA())
cmd.Args = append(cmd.Args, "--cert", neoOpt.Cert())
cmd.Args = append(cmd.Args, "--key", neoOpt.Key())
}
cmd.Args = append(cmd.Args,
opt.Preload,
// 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.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run(); X(err)
neoOpt := NEOSrvOptions{
name: "1",
SSL: ssl,
nmaster: nmaster,
}
return npy
}
// NEO/py
t.Run("py/"+kind, func(t *testing.T) {
t.Helper()
// TODO t.NeedPy(...)
inWorkDir(t, func(workdir string) {
X := xtesting.FatalIf(t)
npy := startNEOpy(t, workdir, opt)
defer func() {
err := npy.Close(); X(err)
}()
f(t, npy)
})
})
// NEO/go
t.Run("go/"+kind, func(t *testing.T) {
t.Helper()
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, opt tOptions) *NEOPySrv {
X := xtesting.FatalIf(t)
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 currently support commit.
npy := startNEOpy(t, workdir, opt)
err := npy.Close(); X(err)
// start NEO/py again to flush ttrans/tobj -> trans/obj tables
// if preload was requested. We need this because currently
// NEO/go does not implement recovery (which is write operation),
// and NEO/py leaves data after ZODB commit in ttrans/tobj (to
// be moved to trans/obj on next ZODB commit). See
// lab.nexedi.com/nexedi/neoppod/commit/7eb7cf1b
npy, err := StartNEOPySrv(neoOpt); X(err)
if opt.Preload != "" {
optRestart := opt
optRestart.Preload = ""
npy = startNEOpy(t, workdir, optRestart)
err = npy.Close(); X(err)
cmd := exec.Command("python", "-c",
"from neo.scripts.neomigrate import main; main()",
"-q",
"-c", npy.clusterName(),
)
if ssl {
cmd.Args = append(cmd.Args, "--ca", neoOpt.CA())
cmd.Args = append(cmd.Args, "--cert", neoOpt.Cert())
cmd.Args = append(cmd.Args, "--key", neoOpt.Key())
}
cmd.Args = append(cmd.Args,
opt.Preload,
// 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.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run(); X(err)
}
return npy
}
// start NEO/go, as the database is created and preloaded
ngo, err := StartNEOGoSrv(neoOpt); X(err)
defer func() {
err := ngo.Close(); X(err)
}()
// NEO/py
t.Run("py/"+kind, func(t *testing.T) {
t.Helper()
// TODO t.NeedPy(...)
inWorkDir(t, func(workdir string) {
X := xtesting.FatalIf(t)
npy := startNEOpy(t, workdir, opt)
defer func() {
err := npy.Close(); 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)
f(t, ngo)
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 currently support commit.
npy := startNEOpy(t, workdir, opt)
err := npy.Close(); X(err)
// start NEO/py again to flush ttrans/tobj -> trans/obj tables
// if preload was requested. We need this because currently
// NEO/go does not implement recovery (which is write operation),
// and NEO/py leaves data after ZODB commit in ttrans/tobj (to
// be moved to trans/obj on next ZODB commit). See
// lab.nexedi.com/nexedi/neoppod/commit/7eb7cf1b
if opt.Preload != "" {
optRestart := opt
optRestart.Preload = ""
npy = startNEOpy(t, workdir, optRestart)
err = npy.Close(); X(err)
}
// start NEO/go, as the database is created and preloaded
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