Skip to content

Commit

Permalink
NonValidator connector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonSw4n committed Jan 20, 2024
1 parent 5290bf9 commit 437e535
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
34 changes: 34 additions & 0 deletions integration_testing/connection_controller_routines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,40 @@ func TestConnectionControllerValidatorConnector(t *testing.T) {
"non-validators node6, node7")
}

func TestConnectionControllerNonValidatorConnector(t *testing.T) {
require := require.New(t)

// Spawn 4 non-validators node1, node2, node3, node4. Set node1's targetOutboundPeers to 3. Then make node1
// create outbound connections to node2, node3, and node4, as well as 2 attempted persistent connections to
// non-existing ips.
node1 := spawnNonValidatorNodeProtocol2(t, 18000, "node1")
node1.Config.TargetOutboundPeers = 3
node2 := spawnNonValidatorNodeProtocol2(t, 18001, "node2")
node3 := spawnNonValidatorNodeProtocol2(t, 18002, "node3")
node4 := spawnNonValidatorNodeProtocol2(t, 18003, "node4")

node2 = startNode(t, node2)
defer node2.Stop()
node3 = startNode(t, node3)
defer node3.Stop()
node4 = startNode(t, node4)
defer node4.Stop()

node1.Config.ConnectIPs = []string{
node2.Listeners[0].Addr().String(),
node3.Listeners[0].Addr().String(),
node4.Listeners[0].Addr().String(),
}
node1 = startNode(t, node1)
defer node1.Stop()

cc := node1.Server.GetConnectionController()
require.NoError(cc.CreateNonValidatorPersistentOutboundConnection("127.0.0.1:18004"))
require.NoError(cc.CreateNonValidatorPersistentOutboundConnection("127.0.0.1:18005"))

waitForCountRemoteNodeIndexer(t, node1, 3, 0, 3, 0)
}

func setGetActiveValidatorImplWithValidatorNodes(t *testing.T, validators ...*cmd.Node) {
require := require.New(t)

Expand Down
4 changes: 2 additions & 2 deletions lib/connection_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ func (cc *ConnectionController) processOutboundConnection(conn Connection) (*Rem
}

if oc.failed {
return nil, fmt.Errorf("ConnectionController.handleOutboundConnection: Failed to connect to peer (%s)",
oc.address.IP.String())
return nil, fmt.Errorf("ConnectionController.handleOutboundConnection: Failed to connect to peer (%s:%v)",
oc.address.IP.String(), oc.address.Port)
}

if !oc.isPersistent {
Expand Down
9 changes: 7 additions & 2 deletions lib/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,13 @@ func (cmgr *ConnectionManager) Start() {

select {
case oc := <-cmgr.outboundConnectionChan:
glog.V(2).Infof("ConnectionManager.Start: Successfully established an outbound connection with "+
"(addr= %v)", oc.connection.RemoteAddr())
if oc.failed {
glog.V(2).Infof("ConnectionManager.Start: Failed to establish an outbound connection with "+
"(id= %v)", oc.attemptId)
} else {
glog.V(2).Infof("ConnectionManager.Start: Successfully established an outbound connection with "+
"(addr= %v)", oc.connection.RemoteAddr())
}
delete(cmgr.outboundConnectionAttempts, oc.attemptId)
cmgr.serverMessageQueue <- &ServerMessage{
Peer: nil,
Expand Down

0 comments on commit 437e535

Please sign in to comment.