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 ...@@ -436,105 +436,108 @@ func withNEOSrv(t *testing.T, f func(t *testing.T, nsrv NEOSrv), optv ...tOption
f(work) 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} { for _, nmaster := range []int{1, 1} {
kind := ""
if ssl { kind = "ssl" } else { kind = "!ssl" }
neoOpt := NEOSrvOptions{ for _, ssl := range []bool{false, true} {
name: "1", kind := ""
SSL: ssl, if ssl { kind = "ssl" } else { kind = "!ssl" }
nmaster: 1,
}
// startNEOpy starts NEO/py server with database in workdir/ neoOpt := NEOSrvOptions{
// and preloads it with data according to opt.Preload. name: "1",
startNEOpy := func(t *testing.T, workdir string, opt tOptions) *NEOPySrv { SSL: ssl,
X := xtesting.FatalIf(t) nmaster: nmaster,
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)
} }
return npy
}
// NEO/py // startNEOpy starts NEO/py server with database in workdir/
t.Run("py/"+kind, func(t *testing.T) { // and preloads it with data according to opt.Preload.
t.Helper() startNEOpy := func(t *testing.T, workdir string, opt tOptions) *NEOPySrv {
// 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) X := xtesting.FatalIf(t)
neoOpt := neoOpt neoOpt := neoOpt
neoOpt.workdir = workdir neoOpt.workdir = workdir
// start NEO/py first. We need it to create the npy, err := StartNEOPySrv(neoOpt); X(err)
// 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 != "" { if opt.Preload != "" {
optRestart := opt cmd := exec.Command("python", "-c",
optRestart.Preload = "" "from neo.scripts.neomigrate import main; main()",
npy = startNEOpy(t, workdir, optRestart) "-q",
err = npy.Close(); X(err) "-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 // NEO/py
ngo, err := StartNEOGoSrv(neoOpt); X(err) t.Run("py/"+kind, func(t *testing.T) {
defer func() { t.Helper()
err := ngo.Close(); X(err) // 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