refactor: inline mockGossipConnection.Connect
Also change Start() order in AddTestGossipConnection to be more pleasing to the eye; the order isn't actually important.
This commit is contained in:
1 parent
9d9768ee6f
commit
5401037743
1 file changed
+8
-13
+8
-13
@@ -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,10 +48,8 @@ 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 {
|
||||||
@@ -65,8 +57,11 @@ func (router *Router) NewTestGossipConnection(r *Router) *mockGossipConnection {
|
|||||||
toPeer := NewPeer(to.Name, to.NickName, to.UID, 0, to.ShortID)
|
toPeer := NewPeer(to.Name, to.NickName, to.UID, 0, to.ShortID)
|
||||||
toPeer = router.Peers.FetchWithDefault(toPeer) // Has side-effect of incrementing refcount
|
toPeer = router.Peers.FetchWithDefault(toPeer) // Has side-effect of incrementing refcount
|
||||||
|
|
||||||
return &mockGossipConnection{
|
conn := &mockGossipConnection{
|
||||||
RemoteConnection{router.Ourself.Peer, toPeer, "", false, true}, router, r, make(chan struct{})}
|
RemoteConnection{router.Ourself.Peer, toPeer, "", false, true}, r, make(chan struct{})}
|
||||||
|
router.Ourself.handleAddConnection(conn)
|
||||||
|
router.Ourself.handleConnectionEstablished(conn)
|
||||||
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (router *Router) DeleteTestGossipConnection(r *Router) {
|
func (router *Router) DeleteTestGossipConnection(r *Router) {
|
||||||
|
|||||||
Reference in new issue
Block a user