Commit 4328ac71 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fb095f94
......@@ -41,9 +41,9 @@ import (
// Verify basic M+S recovery.
func TestClusterRecoveryBasic(t *testing.T) {
Verify(t, func(t0 *tracetest.T, opt tClusterOptions) {
Verify(t, func(t0 *tEnv) {
zback := xfs1back("../zodb/storage/fs1/testdata/1.fs")
t := tNewCluster_MS(t0, "abc1", zback, opt)
t := t0.NewCluster_MS("abc1", zback)
defer t.Stop()
})
}
......@@ -52,7 +52,7 @@ func TestClusterRecoveryBasic(t *testing.T) {
func TestMasterStorage(t *testing.T) {
Verify(t, tracetestMasterStorage)
}
func tracetestMasterStorage(t0 *tracetest.T, opt tClusterOptions) {
func tracetestMasterStorage(t0 *tEnv) {
X := exc.Raiseif
zback := xfs1back("../zodb/storage/fs1/testdata/1.fs")
......@@ -60,7 +60,7 @@ func tracetestMasterStorage(t0 *tracetest.T, opt tClusterOptions) {
lastTid, err := zstor.Sync(bg); X(err)
// create the cluster
t := tNewCluster_MS(t0, "abc1", zback, opt)
t := t0.NewCluster_MS("abc1", zback)
defer t.Stop()
M := t.Master("m")
C := t.NewClient("c", "m:1")
......@@ -359,9 +359,10 @@ func benchmarkGetObject(b *testing.B, opt tClusterOptions, benchit func(xcload1
X := exc.Raiseif
tracetest.Run(b, func(t0 *tracetest.T) {
tenv := &tEnv{t0, opt}
// create test cluster
zback := xfs1back("../zodb/storage/fs1/testdata/1.fs")
t := tNewCluster_MS(t0, "abc1", zback, opt)
t := tenv.NewCluster_MS("abc1", zback)
defer t.Stop()
M := t.Master("m")
......
......@@ -40,17 +40,23 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb"
)
// tEnv is environment for a NEO test.
type tEnv struct {
*tracetest.T // tracetest environment behind tEnv
opt tClusterOptions // by default NEO clusters are created with this options
}
// tCluster is a test NEO cluster.
//
// Create it with tNewCluster.
// Create it with tEnv.NewCluster.
// Create nodes with .NewMaster, .NewStorage and .NewClient.
//
// NOTE network addresses are predictable due to using pipenet/lonet for inter-networking.
//
// XXX text about events tracing
type tCluster struct {
*tracetest.T // original testing env this cluster was created at
*tEnv // original testing env this cluster was created at
name string // name of the cluster
network *virtnet.SubNetwork // nodes interoperate via network
......@@ -96,21 +102,21 @@ type tClusterOptions struct {
Network string
}
// tNewCluster creates new NEO test cluster.
// NewCluster creates new NEO test cluster.
//
// At the end of the test the cluster has to be stopped via t.Stop().
//
// TODO add options describing whether node type X should be created via Go or via Py.
func tNewCluster(ttest *tracetest.T, name string, opt tClusterOptions) *tCluster {
func (t0 *tEnv) NewCluster(name string) *tCluster {
t := &tCluster{
T: ttest,
tEnv: t0,
name: name,
nodeTab: make(map[string]*tNode),
}
// create test network
network := opt.Network
network := t0.opt.Network
if network == "" {
network = "pipenet" // TODO default to lonet if Py nodes will be present
}
......@@ -124,15 +130,15 @@ func tNewCluster(ttest *tracetest.T, name string, opt tClusterOptions) *tCluster
case "lonet":
net, err = lonet.Join(context.Background(), "") // XXX ctx = ttest.Ctx ?
if err != nil {
ttest.Fatal(err)
t0.Fatal(err)
}
}
t.network = net
t.traceOn = true
t.erouter = NewEventRouter()
t.gotracer = NewTraceCollector(ttest)
ttest.SetEventRouter(t.erouter.RouteEvent)
t.gotracer = NewTraceCollector(t0)
t0.SetEventRouter(t.erouter.RouteEvent)
t.gotracer.Attach()
......@@ -390,7 +396,7 @@ func (m *tMaster) Run(ctx context.Context) error {
// Verify verifies f for all combinations of node kinds.
// XXX place
func Verify(t *testing.T, f func(*tracetest.T, tClusterOptions)) {
func Verify(t *testing.T, f func(*tEnv)) {
// TODO verify M=(go|py) x S=(go|py) x ...
// for now we only verify for all combinations of network
......@@ -400,10 +406,14 @@ func Verify(t *testing.T, f func(*tracetest.T, tClusterOptions)) {
Network: network,
}
// TODO don't pass in opt -> instead pass in T which will have .NewCluster() and use T.opt for it.
// TODO don't pass in opt -> instead pass in tEnv which will have .NewCluster() and use T.opt for it.
t.Run("net="+network, func (t *testing.T) {
tracetest.Verify(t, func(t *tracetest.T) {
f(t, opt)
tracetest.Run(t, func(t *tracetest.T) { // XXX -> Verify
tenv := &tEnv{
T: t,
opt: opt,
}
f(tenv)
})
})
}
......@@ -414,8 +424,8 @@ func Verify(t *testing.T, f func(*tracetest.T, tClusterOptions)) {
// tNewCluster_MS starts simple NEO cluster with 1 master and 1 storage nodes.
// The cluster is returned in ready-to-start state.
func tNewCluster_MS(t0 *tracetest.T, name string, Sback storage.Backend, opt tClusterOptions) *tCluster {
t := tNewCluster(t0, name, opt)
func (t0 *tEnv) NewCluster_MS(name string, Sback storage.Backend) *tCluster {
t := t0.NewCluster(name)
t.NewMaster("m")
t.NewStorage("s", "m:1", Sback)
......
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