From 9d9768ee6fe603bfc8b5e412c302ea6cc1d40a50 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 16 Dec 2015 12:33:07 +0000 Subject: [PATCH] fix incorrect peer initialisation on test gossip connections We were creating peers with NewPeerFrom, which copies the Version (but not connections). That's not what happens for a real connection, where remote peers are always created with an initial version of 0. The mistake results in brokenness: when we subsequently receive a topology update for that peer with the same version then we ignore it, even though the update contains connection information which is new to us. Related, it is conceptually wrong to call FetchWithDefault on the remote router. That is not what happens for a real connection - the FetchWithDefault occurs in the symmetric counterpart. --- mesh/gossip_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mesh/gossip_test.go b/mesh/gossip_test.go index 32ab6472..3d1b90f7 100644 --- a/mesh/gossip_test.go +++ b/mesh/gossip_test.go @@ -61,11 +61,9 @@ func AddTestGossipConnection(r1, r2 *Router) { } func (router *Router) NewTestGossipConnection(r *Router) *mockGossipConnection { - fromPeer := NewPeerFrom(router.Ourself.Peer) - toPeer := NewPeerFrom(r.Ourself.Peer) - - r.Peers.FetchWithDefault(fromPeer) // Has side-effect of incrementing refcount - toPeer = router.Peers.FetchWithDefault(toPeer) // + to := 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 return &mockGossipConnection{ RemoteConnection{router.Ourself.Peer, toPeer, "", false, true}, router, r, make(chan struct{})}