Commit 58786531 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f1f7eb02
...@@ -47,6 +47,39 @@ type tEnv struct { ...@@ -47,6 +47,39 @@ type tEnv struct {
opt tClusterOptions // by default NEO clusters are created with this options opt tClusterOptions // by default NEO clusters are created with this options
} }
// tClusterOptions represents options for a test NEO cluster.
type tClusterOptions struct {
// Network forces usage of this kind of network for node inter-networking (pipenet|lonet).
Network string
}
// Verify verifies f for all combinations of NEO environments.
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
// TODO verify enc=(M|N) ?
// for all networks
for _, network := range []string{"pipenet", "lonet"} {
opt := tClusterOptions{
Network: network,
}
t.Run("net="+network, func (t *testing.T) {
tracetest.Verify(t, func(t *tracetest.T) {
tenv := &tEnv{
T: t,
opt: opt,
}
f(tenv)
})
})
}
}
// ----------------------------------------
// tCluster is a test NEO cluster. // tCluster is a test NEO cluster.
// //
// Create it with tEnv.NewCluster. // Create it with tEnv.NewCluster.
...@@ -64,13 +97,13 @@ type tCluster struct { ...@@ -64,13 +97,13 @@ type tCluster struct {
traceOn bool // whether tracing is currently on or off traceOn bool // whether tracing is currently on or off
gotracer *GoTracer // for tracing go nodes gotracer *GoTracer // for tracing go nodes
//tpy *PyTracer // for tracing py nodes TODO //tpy *PyTracer // for tracing py nodes TODO
erouter *EventRouter // to which stream an event should go erouter *EventRouter // to which stream an event should go
tabMu sync.Mutex tabMu sync.Mutex
nodeTab map[string/*node*/]*tNode nodeTab map[string/*node*/]*tNode
runCtx context.Context // runCtx is canceled on .Stop() TODO or test failure runCtx context.Context // runCtx is canceled on .Stop() TODO or test failure
runWG *xsync.WorkGroup // started nodes are .Run() under runWG runWG *xsync.WorkGroup // started nodes are .Run() under runWG
runCancel func() runCancel func()
} }
...@@ -96,12 +129,6 @@ type ITestClient interface { ...@@ -96,12 +129,6 @@ type ITestClient interface {
} }
// tClusterOptions represents options for a test NEO cluster.
type tClusterOptions struct {
// Network forces usage of this kind of network for node inter-networking (pipenet|lonet).
Network string
}
// NewCluster 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().
...@@ -128,7 +155,7 @@ func (t0 *tEnv) NewCluster(name string) *tCluster { ...@@ -128,7 +155,7 @@ func (t0 *tEnv) NewCluster(name string) *tCluster {
case "pipenet": case "pipenet":
net = pipenet.AsVirtNet(pipenet.New("testnet")) net = pipenet.AsVirtNet(pipenet.New("testnet"))
case "lonet": case "lonet":
net, err = lonet.Join(context.Background(), "") // XXX ctx = ttest.Ctx ? net, err = lonet.Join(context.Background(), "") // XXX ctx -> t.Ctx() ?
if err != nil { if err != nil {
t0.Fatal(err) t0.Fatal(err)
} }
...@@ -175,7 +202,7 @@ func (t *tCluster) Stop() { ...@@ -175,7 +202,7 @@ func (t *tCluster) Stop() {
func (t *tCluster) TraceOff() { func (t *tCluster) TraceOff() {
t.traceOn = false t.traceOn = false
t.gotracer.Detach() t.gotracer.Detach()
//XXX t.pytracer.Detach() //t.pytracer.Detach()
t.tabMu.Lock() t.tabMu.Lock()
defer t.tabMu.Unlock() defer t.tabMu.Unlock()
...@@ -187,9 +214,8 @@ func (t *tCluster) TraceOff() { ...@@ -187,9 +214,8 @@ func (t *tCluster) TraceOff() {
// registerNewNode registers new node with given name. // registerNewNode registers new node with given name.
// //
// the node is registered in .nodeTab and .checkTab is populated ... XXX // The node is registered in .nodeTab and .erouter is updated for on-node and node-* events.
// // The node must not be registered before.
// the node must not be registered before.
func (t *tCluster) registerNewNode(name string) *tNode { func (t *tCluster) registerNewNode(name string) *tNode {
t.tabMu.Lock() t.tabMu.Lock()
defer t.tabMu.Unlock() defer t.tabMu.Unlock()
...@@ -362,36 +388,7 @@ func (m *tMaster) Run(ctx context.Context) error { ...@@ -362,36 +388,7 @@ func (m *tMaster) Run(ctx context.Context) error {
return m.Master.Run(ctx, l) return m.Master.Run(ctx, l)
} }
// ------------------- // ----------------------------------------
// Verify verifies f for all combinations of node kinds.
// XXX place
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
// TODO verify enc=(M|N) ?
// for all networks
for _, network := range []string{"pipenet", "lonet"} {
opt := tClusterOptions{
Network: network,
}
t.Run("net="+network, func (t *testing.T) {
tracetest.Verify(t, func(t *tracetest.T) {
tenv := &tEnv{
T: t,
opt: opt,
}
f(tenv)
})
})
}
}
// --------------------
// 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.
...@@ -430,7 +427,7 @@ func (t0 *tEnv) NewCluster_MS(name string, Sback storage.Backend) *tCluster { ...@@ -430,7 +427,7 @@ func (t0 *tEnv) NewCluster_MS(name string, Sback storage.Backend) *tCluster {
})) }))
// M sends nodeTab to S // M sends nodeTab to S
// XXX notifications should go to "m-s/notify" ? // XXX better notifications should go to "m-s/notify" instead ?
t.Expect("m-s", conntx("m:2", "s:2", 0, &proto.NotifyNodeInformation{ t.Expect("m-s", conntx("m:2", "s:2", 0, &proto.NotifyNodeInformation{
IdTime: proto.IdTimeNone, // XXX ? IdTime: proto.IdTimeNone, // XXX ?
NodeList: []proto.NodeInfo{ NodeList: []proto.NodeInfo{
......
...@@ -77,8 +77,8 @@ type eventNodeTab struct { ...@@ -77,8 +77,8 @@ type eventNodeTab struct {
// event: master ready to start changed // event: master ready to start changed
type eventMStartReady struct { type eventMStartReady struct {
Where string // ~ name of the master node Where string // ~ name of the master node
Ready bool Ready bool
} }
func masterStartReady(where string, ready bool) *eventMStartReady { func masterStartReady(where string, ready bool) *eventMStartReady {
......
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