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

.

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