Simplify DeleteTestConnection along the same lines as AddTestConnection
This commit is contained in:
1 parent
08eb90c938
commit
c80bff473f
2 files changed
+8
-8
No files matched your search
@@ -19,7 +19,7 @@ func (peers *Peers) AddTestConnection(p *Peer) {
|
||||
peers.ourself.connectionEstablished(conn)
|
||||
}
|
||||
|
||||
// Add to (peers,p0) a connection from p1 to p2
|
||||
// Add to peers a connection from p1 to p2
|
||||
func (peers *Peers) AddTestRemoteConnection(p1, p2 *Peer) {
|
||||
fromName := p1.Name
|
||||
fromPeer := NewPeer(fromName, p1.UID, 0)
|
||||
@@ -30,12 +30,12 @@ func (peers *Peers) AddTestRemoteConnection(p1, p2 *Peer) {
|
||||
peers.ourself.addConnection(&RemoteConnection{fromPeer, toPeer, ""})
|
||||
}
|
||||
|
||||
func (peers *Peers) DeleteTestConnection(ourself *Peer, peer *Peer) {
|
||||
toName := peer.Name
|
||||
func (peers *Peers) DeleteTestConnection(p *Peer) {
|
||||
toName := p.Name
|
||||
toPeer, _ := peers.Fetch(toName)
|
||||
toPeer.DecrementLocalRefCount()
|
||||
conn, _ := ourself.ConnectionTo(toName)
|
||||
ourself.deleteConnection(conn)
|
||||
conn, _ := peers.ourself.ConnectionTo(toName)
|
||||
peers.ourself.deleteConnection(conn)
|
||||
}
|
||||
|
||||
// mockConnection used in testing is very similar to a
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestPeersEncoding(t *testing.T) {
|
||||
if len(conns) > 0 {
|
||||
n := rand.Intn(len(conns))
|
||||
c := conns[n]
|
||||
ps[c.from].DeleteTestConnection(peer[c.from], peer[c.to])
|
||||
ps[c.from].DeleteTestConnection(peer[c.to])
|
||||
ps[c.from].GarbageCollect()
|
||||
checkApplyUpdate(t, ps[c.from])
|
||||
conns = append(conns[:n], conns[n+1:]...)
|
||||
@@ -103,11 +103,11 @@ func TestPeersGarbageCollection(t *testing.T) {
|
||||
|
||||
// Drop the connection from 2 to 3, and 3 isn't garbage-collected
|
||||
// because 1 has a connection to 3
|
||||
ps2.DeleteTestConnection(p2, p3)
|
||||
ps2.DeleteTestConnection(p3)
|
||||
wt.AssertEmpty(t, ps2.GarbageCollect(), "peers removed")
|
||||
|
||||
// Drop the connection from 1 to 3, and 3 will get removed by
|
||||
// garbage-collection
|
||||
ps1.DeleteTestConnection(p1, p3)
|
||||
ps1.DeleteTestConnection(p3)
|
||||
checkPeerArray(t, ps1.GarbageCollect(), p3)
|
||||
}
|
||||
Reference in new issue
Block a user