-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 104c3ec. Some cleanup and documenting Cleanup; document more nit ConnectIps test Better connectIps test; simplify ConnectionController tests refactor
- Loading branch information
Showing
7 changed files
with
403 additions
and
15 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
integration_testing/connection_controller_routines_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package integration_testing | ||
|
||
import ( | ||
"github.com/deso-protocol/core/bls" | ||
"github.com/deso-protocol/core/cmd" | ||
"github.com/deso-protocol/core/lib" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestConnectionControllerInitiatePersistentConnections(t *testing.T) { | ||
require := require.New(t) | ||
|
||
// NonValidator Node1 will set its --connect-ips to two non-validators node2 and node3, | ||
// and two validators node4 and node5. | ||
node1 := spawnNonValidatorNodeProtocol2(t, 18000, "node1") | ||
node2 := spawnNonValidatorNodeProtocol2(t, 18001, "node2") | ||
node3 := spawnNonValidatorNodeProtocol2(t, 18002, "node3") | ||
blsPriv4, err := bls.NewPrivateKey() | ||
require.NoError(err) | ||
node4 := spawnValidatorNodeProtocol2(t, 18003, "node4", blsPriv4) | ||
blsPriv5, err := bls.NewPrivateKey() | ||
require.NoError(err) | ||
node5 := spawnValidatorNodeProtocol2(t, 18004, "node5", blsPriv5) | ||
|
||
node2 = startNode(t, node2) | ||
node3 = startNode(t, node3) | ||
node4 = startNode(t, node4) | ||
node5 = startNode(t, node5) | ||
|
||
oldGetActiveValidatorImpl := lib.GetActiveValidatorImpl | ||
defer func() { | ||
setGetActiveValidatorImpl(oldGetActiveValidatorImpl) | ||
}() | ||
setGetActiveValidatorImpl(func() map[bls.SerializedPublicKey]*lib.ValidatorEntry { | ||
return map[bls.SerializedPublicKey]*lib.ValidatorEntry{ | ||
blsPriv4.PublicKey().Serialize(): createSimpleValidatorEntry(node4), | ||
blsPriv5.PublicKey().Serialize(): createSimpleValidatorEntry(node5), | ||
} | ||
}) | ||
|
||
node1.Config.ConnectIPs = []string{ | ||
node2.Listeners[0].Addr().String(), | ||
node3.Listeners[0].Addr().String(), | ||
node4.Listeners[0].Addr().String(), | ||
node5.Listeners[0].Addr().String(), | ||
} | ||
node1 = startNode(t, node1) | ||
waitForNonValidatorOutboundConnection(t, node1, node2) | ||
waitForNonValidatorOutboundConnection(t, node1, node3) | ||
waitForValidatorConnection(t, node1, node4) | ||
waitForValidatorConnection(t, node1, node5) | ||
waitForValidatorConnection(t, node4, node5) | ||
waitForCountRemoteNodeIndexer(t, node1, 4, 2, 2, 0) | ||
waitForCountRemoteNodeIndexer(t, node2, 1, 0, 0, 1) | ||
waitForCountRemoteNodeIndexer(t, node3, 1, 0, 0, 1) | ||
waitForCountRemoteNodeIndexer(t, node4, 2, 1, 0, 1) | ||
waitForCountRemoteNodeIndexer(t, node5, 2, 1, 0, 1) | ||
node1.Stop() | ||
t.Logf("Test #1 passed | Successfully run non-validator node1 with --connect-ips set to node2, node3, node4, node5") | ||
|
||
// Now try again with a validator node6, with connect-ips set to node2, node3, node4, node5. | ||
blsPriv6, err := bls.NewPrivateKey() | ||
require.NoError(err) | ||
node6 := spawnValidatorNodeProtocol2(t, 18005, "node6", blsPriv6) | ||
node6.Config.ConnectIPs = []string{ | ||
node2.Listeners[0].Addr().String(), | ||
node3.Listeners[0].Addr().String(), | ||
node4.Listeners[0].Addr().String(), | ||
node5.Listeners[0].Addr().String(), | ||
} | ||
node6 = startNode(t, node6) | ||
setGetActiveValidatorImpl(func() map[bls.SerializedPublicKey]*lib.ValidatorEntry { | ||
return map[bls.SerializedPublicKey]*lib.ValidatorEntry{ | ||
blsPriv4.PublicKey().Serialize(): createSimpleValidatorEntry(node4), | ||
blsPriv5.PublicKey().Serialize(): createSimpleValidatorEntry(node5), | ||
blsPriv6.PublicKey().Serialize(): createSimpleValidatorEntry(node6), | ||
} | ||
}) | ||
waitForNonValidatorOutboundConnection(t, node6, node2) | ||
waitForNonValidatorOutboundConnection(t, node6, node3) | ||
waitForValidatorConnection(t, node6, node4) | ||
waitForValidatorConnection(t, node6, node5) | ||
waitForValidatorConnection(t, node4, node5) | ||
waitForCountRemoteNodeIndexer(t, node6, 4, 2, 2, 0) | ||
waitForCountRemoteNodeIndexer(t, node2, 1, 1, 0, 0) | ||
waitForCountRemoteNodeIndexer(t, node3, 1, 1, 0, 0) | ||
waitForCountRemoteNodeIndexer(t, node4, 2, 2, 0, 0) | ||
waitForCountRemoteNodeIndexer(t, node5, 2, 2, 0, 0) | ||
node6.Stop() | ||
node2.Stop() | ||
node3.Stop() | ||
node4.Stop() | ||
node5.Stop() | ||
t.Logf("Test #2 passed | Successfully run validator node6 with --connect-ips set to node2, node3, node4, node5") | ||
} | ||
|
||
func setGetActiveValidatorImpl(mapping func() map[bls.SerializedPublicKey]*lib.ValidatorEntry) { | ||
lib.GetActiveValidatorImpl = mapping | ||
} | ||
|
||
func createSimpleValidatorEntry(node *cmd.Node) *lib.ValidatorEntry { | ||
return &lib.ValidatorEntry{ | ||
Domains: [][]byte{[]byte(node.Listeners[0].Addr().String())}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.