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 {
|
||||
RemoteConnection
|
||||
router *Router
|
||||
dest *Router
|
||||
start chan struct{}
|
||||
dest *Router
|
||||
start chan struct{}
|
||||
}
|
||||
|
||||
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() {
|
||||
close(conn.start)
|
||||
}
|
||||
@@ -54,10 +48,8 @@ func sendPendingGossip(routers ...*Router) {
|
||||
func AddTestGossipConnection(r1, r2 *Router) {
|
||||
c1 := r1.NewTestGossipConnection(r2)
|
||||
c2 := r2.NewTestGossipConnection(r1)
|
||||
c1.Connect()
|
||||
c2.Start()
|
||||
c2.Connect()
|
||||
c1.Start()
|
||||
c2.Start()
|
||||
}
|
||||
|
||||
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 = router.Peers.FetchWithDefault(toPeer) // Has side-effect of incrementing refcount
|
||||
|
||||
return &mockGossipConnection{
|
||||
RemoteConnection{router.Ourself.Peer, toPeer, "", false, true}, router, r, make(chan struct{})}
|
||||
conn := &mockGossipConnection{
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user