Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoS NetworkManager Fix Integration Tests #960

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 33 additions & 102 deletions integration_testing/blocksync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package integration_testing

import (
"fmt"
"github.com/deso-protocol/core/cmd"
"github.com/deso-protocol/core/lib"
"github.com/stretchr/testify/require"
"os"
"testing"
)

Expand All @@ -16,40 +12,22 @@ import (
// 4. node2 syncs MaxSyncBlockHeight blocks from node1.
// 5. compare node1 db matches node2 db.
func TestSimpleBlockSync(t *testing.T) {
require := require.New(t)
_ = require

dbDir1 := getDirectory(t)
dbDir2 := getDirectory(t)
defer os.RemoveAll(dbDir1)
defer os.RemoveAll(dbDir2)

config1 := generateConfig(t, 18000, dbDir1, 10)
config1.SyncType = lib.NodeSyncTypeBlockSync
config2 := generateConfig(t, 18001, dbDir2, 10)
config2.SyncType = lib.NodeSyncTypeBlockSync

config1.ConnectIPs = []string{"deso-seed-2.io:17000"}

node1 := cmd.NewNode(config1)
node2 := cmd.NewNode(config2)

node1 := spawnNodeProtocol1(t, 18000, "node1")
node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"}
node1 = startNode(t, node1)
node2 = startNode(t, node2)

// wait for node1 to sync blocks
waitForNodeToFullySync(node1)

// TODO: Dial an outbound connection from node2 to node1
// Fix other integration tests.
node2 := spawnNodeProtocol1(t, 18001, "node2")
node2.Config.ConnectIPs = []string{"127.0.0.1:18000"}
node2 = startNode(t, node2)

// wait for node2 to sync blocks.
waitForNodeToFullySync(node2)

compareNodesByDB(t, node1, node2, 0)
fmt.Println("Databases match!")
node1.Stop()
node2.Stop()
}

// TestSimpleSyncRestart tests if a node can successfully restart while syncing blocks.
Expand All @@ -61,46 +39,26 @@ func TestSimpleBlockSync(t *testing.T) {
// 6. node2 reconnects with node1 and syncs remaining blocks.
// 7. compare node1 db matches node2 db.
func TestSimpleSyncRestart(t *testing.T) {
require := require.New(t)
_ = require

dbDir1 := getDirectory(t)
dbDir2 := getDirectory(t)
defer os.RemoveAll(dbDir1)
defer os.RemoveAll(dbDir2)

config1 := generateConfig(t, 18000, dbDir1, 10)
config1.SyncType = lib.NodeSyncTypeBlockSync
config2 := generateConfig(t, 18001, dbDir2, 10)
config2.SyncType = lib.NodeSyncTypeBlockSync

config1.ConnectIPs = []string{"deso-seed-2.io:17000"}

node1 := cmd.NewNode(config1)
node2 := cmd.NewNode(config2)

node1 := spawnNodeProtocol1(t, 18000, "node1")
node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"}
node1 = startNode(t, node1)
node2 = startNode(t, node2)

// wait for node1 to sync blocks
waitForNodeToFullySync(node1)

// bridge the nodes together.
bridge := NewConnectionBridge(node1, node2)
require.NoError(bridge.Start())
node2 := spawnNodeProtocol1(t, 18001, "node2")
node2.Config.ConnectIPs = []string{"127.0.0.1:18000"}
node2 = startNode(t, node2)

randomHeight := randomUint32Between(t, 10, config2.MaxSyncBlockHeight)
fmt.Println("Random height for a restart (re-use if test failed):", randomHeight)
randomHeight := randomUint32Between(t, 10, node2.Config.MaxSyncBlockHeight)
t.Logf("Random height for a restart (re-use if test failed): %v", randomHeight)
// Reboot node2 at a specific height and reconnect it with node1
node2, bridge = restartAtHeightAndReconnectNode(t, node2, node1, bridge, randomHeight)
node2 = restartAtHeight(t, node2, randomHeight)
waitForNodeToFullySync(node2)

compareNodesByDB(t, node1, node2, 0)
fmt.Println("Random restart successful! Random height was", randomHeight)
fmt.Println("Databases match!")
bridge.Disconnect()
node1.Stop()
node2.Stop()
t.Logf("Random restart successful! Random height was: %v", randomHeight)
t.Logf("Databases match!")
}

// TestSimpleSyncDisconnectWithSwitchingToNewPeer tests if a node can successfully restart while syncing blocks, and
Expand All @@ -114,62 +72,35 @@ func TestSimpleSyncRestart(t *testing.T) {
// 7. compare node1 state matches node2 state.
// 8. compare node3 state matches node2 state.
func TestSimpleSyncDisconnectWithSwitchingToNewPeer(t *testing.T) {
require := require.New(t)
_ = require

dbDir1 := getDirectory(t)
dbDir2 := getDirectory(t)
dbDir3 := getDirectory(t)
defer os.RemoveAll(dbDir1)
defer os.RemoveAll(dbDir2)
defer os.RemoveAll(dbDir3)

config1 := generateConfig(t, 18000, dbDir1, 10)
config1.SyncType = lib.NodeSyncTypeBlockSync
config2 := generateConfig(t, 18001, dbDir2, 10)
config2.SyncType = lib.NodeSyncTypeBlockSync
config3 := generateConfig(t, 18002, dbDir3, 10)
config3.SyncType = lib.NodeSyncTypeBlockSync

config1.ConnectIPs = []string{"deso-seed-2.io:17000"}
config3.ConnectIPs = []string{"deso-seed-2.io:17000"}

node1 := cmd.NewNode(config1)
node2 := cmd.NewNode(config2)
node3 := cmd.NewNode(config3)

node1 := spawnNodeProtocol1(t, 18000, "node1")
node1.Config.ConnectIPs = []string{"deso-seed-2.io:17000"}
node1 = startNode(t, node1)
node2 = startNode(t, node2)
node3 = startNode(t, node3)

// wait for node1 to sync blocks
waitForNodeToFullySync(node1)

node3 := spawnNodeProtocol1(t, 18002, "node3")
node3.Config.ConnectIPs = []string{"deso-seed-2.io:17000"}
node3 = startNode(t, node3)

// wait for node3 to sync blocks
waitForNodeToFullySync(node3)

// bridge the nodes together.
bridge12 := NewConnectionBridge(node1, node2)
require.NoError(bridge12.Start())

randomHeight := randomUint32Between(t, 10, config2.MaxSyncBlockHeight)
fmt.Println("Random height for a restart (re-use if test failed):", randomHeight)
disconnectAtBlockHeight(node2, bridge12, randomHeight)
node2 := spawnNodeProtocol1(t, 18001, "node2")
node2.Config.ConnectIPs = []string{"127.0.0.1:18000"}
node2 = startNode(t, node2)

// bridge the nodes together.
bridge23 := NewConnectionBridge(node2, node3)
require.NoError(bridge23.Start())
randomHeight := randomUint32Between(t, 10, node2.Config.MaxSyncBlockHeight)
t.Logf("Random height for a restart (re-use if test failed): %v", randomHeight)

// Reboot node2 at a specific height and reconnect it with node1
//node2, bridge12 = restartAtHeightAndReconnectNode(t, node2, node1, bridge12, randomHeight)
// Reboot node2 at a specific height and reconnect it with node3
node2 = shutdownAtHeight(t, node2, randomHeight)
node2.Config.ConnectIPs = []string{"127.0.0.1:18002"}
node2 = startNode(t, node2)
waitForNodeToFullySync(node2)

compareNodesByDB(t, node1, node2, 0)
compareNodesByDB(t, node3, node2, 0)
fmt.Println("Random restart successful! Random height was", randomHeight)
fmt.Println("Databases match!")
bridge12.Disconnect()
bridge23.Disconnect()
node1.Stop()
node2.Stop()
node3.Stop()
t.Logf("Random restart successful! Random height was %v", randomHeight)
t.Logf("Databases match!")
}
9 changes: 0 additions & 9 deletions integration_testing/connection_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ func ReadWithTimeout(readFunc func() error, readTimeout time.Duration) error {
func (bridge *ConnectionBridge) startConnection(connection *lib.Peer, otherNode *cmd.Node) error {
// Prepare the version message.
versionMessage := bridge.getVersionMessage(otherNode)
connection.VersionNonceSent = versionMessage.Nonce

// Send the version message.
fmt.Println("Sending version message:", versionMessage, versionMessage.LatestBlockHeight)
Expand All @@ -222,7 +221,6 @@ func (bridge *ConnectionBridge) startConnection(connection *lib.Peer, otherNode
return err
}

connection.VersionNonceReceived = verMsg.Nonce
connection.TimeConnected = time.Unix(verMsg.TstampSecs, 0)
connection.TimeOffsetSecs = verMsg.TstampSecs - time.Now().Unix()
return nil
Expand All @@ -233,7 +231,6 @@ func (bridge *ConnectionBridge) startConnection(connection *lib.Peer, otherNode

// Now prepare the verack message.
verackMsg := lib.NewMessage(lib.MsgTypeVerack)
verackMsg.(*lib.MsgDeSoVerack).NonceReceived = connection.VersionNonceReceived

// And send it to the connection.
if err := connection.WriteDeSoMessage(verackMsg); err != nil {
Expand All @@ -251,17 +248,11 @@ func (bridge *ConnectionBridge) startConnection(connection *lib.Peer, otherNode
if msg.GetMsgType() != lib.MsgTypeVerack {
return fmt.Errorf("message is not verack! Type: %v", msg.GetMsgType())
}
verackMsg := msg.(*lib.MsgDeSoVerack)
if verackMsg.NonceReceived != connection.VersionNonceSent {
return fmt.Errorf("verack message nonce doesn't match (received: %v, sent: %v)",
verackMsg.NonceReceived, connection.VersionNonceSent)
}
return nil
}, lib.DeSoMainnetParams.VersionNegotiationTimeout); err != nil {

return err
}
connection.VersionNegotiated = true

return nil
}
Expand Down
Loading
Loading