Merge pull request #1796 from weaveworks/gossip-test-connection-mistake
fix gossip test connection peer initialisation and connection deletion mistakes
This commit is contained in:
commit
f09d87c112
1 file changed
+14
-33
+14
-33
@@ -13,9 +13,8 @@ import (
|
|||||||
|
|
||||||
type mockGossipConnection struct {
|
type mockGossipConnection struct {
|
||||||
RemoteConnection
|
RemoteConnection
|
||||||
router *Router
|
dest *Router
|
||||||
dest *Router
|
start chan struct{}
|
||||||
start chan struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTestRouter(name string) *Router {
|
func NewTestRouter(name string) *Router {
|
||||||
@@ -32,11 +31,6 @@ func (conn *mockGossipConnection) SendProtocolMsg(protocolMsg ProtocolMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *mockGossipConnection) Connect() {
|
|
||||||
conn.router.Ourself.handleAddConnection(conn)
|
|
||||||
conn.router.Ourself.handleConnectionEstablished(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conn *mockGossipConnection) Start() {
|
func (conn *mockGossipConnection) Start() {
|
||||||
close(conn.start)
|
close(conn.start)
|
||||||
}
|
}
|
||||||
@@ -54,34 +48,26 @@ func sendPendingGossip(routers ...*Router) {
|
|||||||
func AddTestGossipConnection(r1, r2 *Router) {
|
func AddTestGossipConnection(r1, r2 *Router) {
|
||||||
c1 := r1.NewTestGossipConnection(r2)
|
c1 := r1.NewTestGossipConnection(r2)
|
||||||
c2 := r2.NewTestGossipConnection(r1)
|
c2 := r2.NewTestGossipConnection(r1)
|
||||||
c1.Connect()
|
|
||||||
c2.Start()
|
|
||||||
c2.Connect()
|
|
||||||
c1.Start()
|
c1.Start()
|
||||||
|
c2.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (router *Router) NewTestGossipConnection(r *Router) *mockGossipConnection {
|
func (router *Router) NewTestGossipConnection(r *Router) *mockGossipConnection {
|
||||||
fromPeer := NewPeerFrom(router.Ourself.Peer)
|
to := r.Ourself.Peer
|
||||||
toPeer := NewPeerFrom(r.Ourself.Peer)
|
toPeer := NewPeer(to.Name, to.NickName, to.UID, 0, to.ShortID)
|
||||||
|
toPeer = router.Peers.FetchWithDefault(toPeer) // Has side-effect of incrementing refcount
|
||||||
|
|
||||||
r.Peers.FetchWithDefault(fromPeer) // Has side-effect of incrementing refcount
|
conn := &mockGossipConnection{
|
||||||
toPeer = router.Peers.FetchWithDefault(toPeer) //
|
RemoteConnection{router.Ourself.Peer, toPeer, "", false, true}, r, make(chan struct{})}
|
||||||
|
router.Ourself.handleAddConnection(conn)
|
||||||
return &mockGossipConnection{
|
router.Ourself.handleConnectionEstablished(conn)
|
||||||
RemoteConnection{router.Ourself.Peer, toPeer, "", false, true}, router, r, make(chan struct{})}
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (router *Router) DeleteTestGossipConnection(r *Router) {
|
func (router *Router) DeleteTestGossipConnection(r *Router) {
|
||||||
fromName := router.Ourself.Peer.Name
|
|
||||||
toName := r.Ourself.Peer.Name
|
toName := r.Ourself.Peer.Name
|
||||||
|
|
||||||
fromPeer := r.Peers.Fetch(fromName)
|
|
||||||
toPeer := router.Peers.Fetch(toName)
|
|
||||||
|
|
||||||
r.Peers.Dereference(fromPeer)
|
|
||||||
router.Peers.Dereference(toPeer)
|
|
||||||
|
|
||||||
conn, _ := router.Ourself.ConnectionTo(toName)
|
conn, _ := router.Ourself.ConnectionTo(toName)
|
||||||
|
router.Peers.Dereference(conn.Remote())
|
||||||
router.Ourself.handleDeleteConnection(conn)
|
router.Ourself.handleDeleteConnection(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,15 +129,10 @@ func TestGossipTopology(t *testing.T) {
|
|||||||
// Drop the connection from 1 to 3
|
// Drop the connection from 1 to 3
|
||||||
r1.DeleteTestGossipConnection(r3)
|
r1.DeleteTestGossipConnection(r3)
|
||||||
sendPendingGossip(r1, r2, r3)
|
sendPendingGossip(r1, r2, r3)
|
||||||
checkTopology(t, r1, r1.tp(r2), r2.tp(r1), r3.tp(r1, r2))
|
checkTopology(t, r1, r1.tp(r2), r2.tp(r1))
|
||||||
checkTopology(t, r2, r1.tp(r2), r2.tp(r1), r3.tp(r1, r2))
|
checkTopology(t, r2, r1.tp(r2), r2.tp(r1))
|
||||||
// r3 still thinks r1 has a connection to it
|
// r3 still thinks r1 has a connection to it
|
||||||
checkTopology(t, r3, r1.tp(r2, r3), r2.tp(r1), r3.tp(r1, r2))
|
checkTopology(t, r3, r1.tp(r2, r3), r2.tp(r1), r3.tp(r1, r2))
|
||||||
|
|
||||||
// On a timer, r3 will gossip to r1
|
|
||||||
r3.SendAllGossip()
|
|
||||||
sendPendingGossip(r1, r2, r3)
|
|
||||||
checkTopology(t, r1, r1.tp(r2), r2.tp(r1), r3.tp(r1, r2))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGossipSurrogate(t *testing.T) {
|
func TestGossipSurrogate(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user