Commit eff3e3e4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3229af24
......@@ -27,6 +27,7 @@ import (
//"bytes"
"context"
//"io"
"math"
"net"
//"reflect"
"testing"
......@@ -107,6 +108,25 @@ func (t *MyTracer) traceNode(nt *neo.NodeTable, n *neo.Node) {
}
// vclock is a virtual clock
// XXX place -> util?
type vclock struct {
t float64
}
func (c *vclock) monotime() float64 {
c.t += 1E-2
return c.t
}
func (c *vclock) tick() { // XXX do we need tick?
t := math.Ceil(c.t)
if !(t > c.t) {
t += 1
}
c.t = t
}
//trace:import "lab.nexedi.com/kirr/neo/go/neo"
// M drives cluster with 1 S through recovery -> verification -> service -> shutdown
......@@ -181,7 +201,9 @@ func TestMasterStorage(t *testing.T) {
wg := &xsync.WorkGroup{}
// start master
Mclock := &vclock{}
M := NewMaster("abc1", ":1", Mhost)
M.monotime = Mclock.monotime
Mctx, Mcancel := context.WithCancel(context.Background())
wg.Gox(func() {
err := M.Run(Mctx)
......@@ -224,7 +246,7 @@ func TestMasterStorage(t *testing.T) {
IdTimestamp: 0,
}))
tc.Expect(node(M.nodeTab, "s:1", neo.STORAGE, 1, neo.PENDING, 0.0)) // XXX t
tc.Expect(node(M.nodeTab, "s:1", neo.STORAGE, 1, neo.PENDING, 0.01))
tc.Expect(conntx("m:2", "s:2", 1, &neo.AcceptIdentification{
NodeType: neo.MASTER,
......
......@@ -65,6 +65,10 @@ type Master struct {
// channels from workers directly serving peers to main driver
nodeCome chan nodeCome // node connected XXX -> acceptq?
nodeLeave chan nodeLeave // node disconnected XXX -> don't need
// so tests could override
monotime func() float64
}
......@@ -105,6 +109,8 @@ func NewMaster(clusterName, serveAddr string, net xnet.Networker) *Master {
nodeCome: make(chan nodeCome),
nodeLeave: make(chan nodeLeave),
monotime: monotime,
}
m.clusterState = -1 // invalid
......@@ -905,7 +911,7 @@ func (m *Master) identify(ctx context.Context, n nodeCome) (node *neo.Node, resp
Address: n.idReq.Address,
NodeUUID: uuid,
NodeState: nodeState,
IdTimestamp: monotime(),
IdTimestamp: m.monotime(),
}
node = m.nodeTab.Update(nodeInfo, n.conn) // NOTE this notifies all nodeTab subscribers
......
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