Simplify DeleteTestConnection along the same lines as AddTestConnection

This commit is contained in:
Bryan Boreham committed 2015-01-26 14:03:32 +00:00
1 parent 08eb90c938
commit c80bff473f
2 files changed
+8 -8

No files matched your search

+5 -5
View File
@@ -19,7 +19,7 @@ func (peers *Peers) AddTestConnection(p *Peer) {
peers.ourself.connectionEstablished(conn) 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) { func (peers *Peers) AddTestRemoteConnection(p1, p2 *Peer) {
fromName := p1.Name fromName := p1.Name
fromPeer := NewPeer(fromName, p1.UID, 0) fromPeer := NewPeer(fromName, p1.UID, 0)
@@ -30,12 +30,12 @@ func (peers *Peers) AddTestRemoteConnection(p1, p2 *Peer) {
peers.ourself.addConnection(&RemoteConnection{fromPeer, toPeer, ""}) peers.ourself.addConnection(&RemoteConnection{fromPeer, toPeer, ""})
} }
func (peers *Peers) DeleteTestConnection(ourself *Peer, peer *Peer) { func (peers *Peers) DeleteTestConnection(p *Peer) {
toName := peer.Name toName := p.Name
toPeer, _ := peers.Fetch(toName) toPeer, _ := peers.Fetch(toName)
toPeer.DecrementLocalRefCount() toPeer.DecrementLocalRefCount()
conn, _ := ourself.ConnectionTo(toName) conn, _ := peers.ourself.ConnectionTo(toName)
ourself.deleteConnection(conn) peers.ourself.deleteConnection(conn)
} }
// mockConnection used in testing is very similar to a // mockConnection used in testing is very similar to a
+3 -3
View File
@@ -62,7 +62,7 @@ func TestPeersEncoding(t *testing.T) {
if len(conns) > 0 { if len(conns) > 0 {
n := rand.Intn(len(conns)) n := rand.Intn(len(conns))
c := conns[n] c := conns[n]
ps[c.from].DeleteTestConnection(peer[c.from], peer[c.to]) ps[c.from].DeleteTestConnection(peer[c.to])
ps[c.from].GarbageCollect() ps[c.from].GarbageCollect()
checkApplyUpdate(t, ps[c.from]) checkApplyUpdate(t, ps[c.from])
conns = append(conns[:n], conns[n+1:]...) 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 // Drop the connection from 2 to 3, and 3 isn't garbage-collected
// because 1 has a connection to 3 // because 1 has a connection to 3
ps2.DeleteTestConnection(p2, p3) ps2.DeleteTestConnection(p3)
wt.AssertEmpty(t, ps2.GarbageCollect(), "peers removed") wt.AssertEmpty(t, ps2.GarbageCollect(), "peers removed")
// Drop the connection from 1 to 3, and 3 will get removed by // Drop the connection from 1 to 3, and 3 will get removed by
// garbage-collection // garbage-collection
ps1.DeleteTestConnection(p1, p3) ps1.DeleteTestConnection(p3)
checkPeerArray(t, ps1.GarbageCollect(), p3) checkPeerArray(t, ps1.GarbageCollect(), p3)
} }