Skip to content

Commit

Permalink
Refactor Mocknet FullMeshLinked and FullMeshConnected
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: rht <[email protected]>
  • Loading branch information
rht committed Aug 28, 2015
1 parent b55cf12 commit ef0bf10
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
1 change: 1 addition & 0 deletions p2p/net/mock/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Mocknet interface {
DisconnectPeers(peer.ID, peer.ID) error
DisconnectNets(inet.Network, inet.Network) error
LinkAll() error
ConnectAll() error
}

// LinkOptions are used to change aspects of the links.
Expand Down
21 changes: 4 additions & 17 deletions p2p/net/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,9 @@ func FullMeshLinked(ctx context.Context, n int) (Mocknet, error) {
return nil, err
}

nets := m.Nets()
for _, n1 := range nets {
for _, n2 := range nets {
// yes, even self.
if _, err := m.LinkNets(n1, n2); err != nil {
return nil, err
}
}
if err := m.LinkAll(); err != nil {
return nil, err
}

return m, nil
}

Expand All @@ -50,14 +43,8 @@ func FullMeshConnected(ctx context.Context, n int) (Mocknet, error) {
return nil, err
}

nets := m.Nets()
for _, n1 := range nets {
for _, n2 := range nets {
if _, err := m.ConnectNets(n1, n2); err != nil {
return nil, err
}
}
if err := m.ConnectAll(); err != nil {
return nil, err
}

return m, nil
}
11 changes: 2 additions & 9 deletions p2p/net/mock/mock_notif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ func TestNotifications(t *testing.T) {
}

// connect all
for _, n1 := range nets {
for _, n2 := range nets {
if n1 == n2 {
continue
}
if _, err := mn.ConnectNets(n1, n2); err != nil {
t.Fatal(err)
}
}
if err := mn.ConnectAll(); err != nil {
t.Fatal(err)
}

// test everyone got the correct connection opened calls
Expand Down

0 comments on commit ef0bf10

Please sign in to comment.