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

Merge dev into feat partial mb execution 24.05.2022 #4109

Merged
Changes from all 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
37 changes: 24 additions & 13 deletions heartbeat/monitor/monitor_test.go
Original file line number Diff line number Diff line change
@@ -185,9 +185,13 @@ func TestHeartbeatV2Monitor_parseMessage(t *testing.T) {
numInstances := make(map[string]uint64)
message := createHeartbeatMessage(true)
providedPid := core.PeerID("pid")
providedMap := map[string]struct{}{
providedPid.Pretty(): {},
}
hb, err := monitor.parseMessage(providedPid, message, numInstances)
assert.Nil(t, err)
checkResults(t, *message, hb, true, providedPid, 0)
checkResults(t, *message, hb, true, providedMap, 0)
assert.Equal(t, 0, len(providedMap))
pid := args.PubKeyConverter.Encode(providedPkBytes)
entries, ok := numInstances[pid]
assert.True(t, ok)
@@ -257,13 +261,14 @@ func TestHeartbeatV2Monitor_GetHeartbeats(t *testing.T) {
}
providedStatuses := []bool{true, true, false}
numOfMessages := len(providedStatuses)
providedPids := make([]core.PeerID, numOfMessages)
providedPids := make(map[string]struct{}, numOfMessages)
providedMessages := make([]*heartbeat.HeartbeatV2, numOfMessages)
for i := 0; i < numOfMessages; i++ {
providedPids[i] = core.PeerID(fmt.Sprintf("%s%d", "pid", i))
pid := core.PeerID(fmt.Sprintf("%s%d", "pid", i))
providedPids[pid.Pretty()] = struct{}{}
providedMessages[i] = createHeartbeatMessage(providedStatuses[i])

args.Cache.Put(providedPids[i].Bytes(), providedMessages[i], providedMessages[i].Size())
args.Cache.Put(pid.Bytes(), providedMessages[i], providedMessages[i].Size())
}

monitor, _ := NewHeartbeatV2Monitor(args)
@@ -272,27 +277,30 @@ func TestHeartbeatV2Monitor_GetHeartbeats(t *testing.T) {
heartbeats := monitor.GetHeartbeats()
assert.Equal(t, args.Cache.Len()-1, len(heartbeats))
for i := 0; i < len(heartbeats); i++ {
checkResults(t, *providedMessages[i], heartbeats[i], providedStatuses[i], providedPids[i], 1)
checkResults(t, *providedMessages[i], heartbeats[i], providedStatuses[i], providedPids, 1)
}
assert.Equal(t, 1, len(providedPids)) // one message is skipped
})
t.Run("should work", func(t *testing.T) {
t.Parallel()
args := createMockHeartbeatV2MonitorArgs()
providedStatuses := []bool{true, true, true}
numOfMessages := len(providedStatuses)
providedPids := make([]core.PeerID, numOfMessages)
providedPids := make(map[string]struct{}, numOfMessages)
providedMessages := make([]*heartbeat.HeartbeatV2, numOfMessages)
for i := 0; i < numOfMessages; i++ {
providedPids[i] = core.PeerID(fmt.Sprintf("%s%d", "pid", i))
pid := core.PeerID(fmt.Sprintf("%s%d", "pid", i))
providedPids[pid.Pretty()] = struct{}{}
providedMessages[i] = createHeartbeatMessage(providedStatuses[i])

args.Cache.Put(providedPids[i].Bytes(), providedMessages[i], providedMessages[i].Size())
args.Cache.Put(pid.Bytes(), providedMessages[i], providedMessages[i].Size())
}
counter := 0
args.PeerShardMapper = &processMocks.PeerShardMapperStub{
GetPeerInfoCalled: func(pid core.PeerID) core.P2PPeerInfo {
// Only first entry is unique, then all should have same pk
var info core.P2PPeerInfo
if pid == providedPids[0] {
if counter == 0 {
info = core.P2PPeerInfo{
PkBytes: pid.Bytes(),
}
@@ -301,7 +309,7 @@ func TestHeartbeatV2Monitor_GetHeartbeats(t *testing.T) {
PkBytes: []byte("same pk"),
}
}

counter++
return info
},
}
@@ -316,18 +324,21 @@ func TestHeartbeatV2Monitor_GetHeartbeats(t *testing.T) {
if i > 0 {
numInstances = 2
}
checkResults(t, *providedMessages[i], heartbeats[i], providedStatuses[i], providedPids[i], numInstances)
checkResults(t, *providedMessages[i], heartbeats[i], providedStatuses[i], providedPids, numInstances)
}
assert.Equal(t, 0, len(providedPids))
})
}

func checkResults(t *testing.T, message heartbeat.HeartbeatV2, hb data.PubKeyHeartbeat, isActive bool, pid core.PeerID, numInstances uint64) {
func checkResults(t *testing.T, message heartbeat.HeartbeatV2, hb data.PubKeyHeartbeat, isActive bool, providedPids map[string]struct{}, numInstances uint64) {
assert.Equal(t, isActive, hb.IsActive)
assert.Equal(t, message.VersionNumber, hb.VersionNumber)
assert.Equal(t, message.NodeDisplayName, hb.NodeDisplayName)
assert.Equal(t, message.Identity, hb.Identity)
assert.Equal(t, message.Nonce, hb.Nonce)
assert.Equal(t, message.PeerSubType, hb.PeerSubType)
assert.Equal(t, numInstances, hb.NumInstances)
assert.Equal(t, pid.Pretty(), hb.PidString)
_, ok := providedPids[hb.PidString]
assert.True(t, ok)
delete(providedPids, hb.PidString)
}
6 changes: 3 additions & 3 deletions integrationTests/node/heartbeatV2/heartbeatV2_test.go
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ func TestHeartbeatV2_AllPeersSendMessages(t *testing.T) {
connectNodes(nodes, interactingNodes)

// Wait for messages to broadcast
time.Sleep(time.Second * 5)
time.Sleep(time.Second * 15)

for i := 0; i < len(nodes); i++ {
nodes[i].Close()
@@ -53,7 +53,7 @@ func TestHeartbeatV2_PeerJoiningLate(t *testing.T) {
connectNodes(nodes, interactingNodes)

// Wait for messages to broadcast
time.Sleep(time.Second * 10)
time.Sleep(time.Second * 15)

// Check sent messages
maxMessageAgeAllowed := time.Second * 5
@@ -64,7 +64,7 @@ func TestHeartbeatV2_PeerJoiningLate(t *testing.T) {
nodes = append(nodes, delayedNode)
connectNodes(nodes, len(nodes))
// Wait for messages to broadcast and requests to finish
time.Sleep(time.Second * 10)
time.Sleep(time.Second * 15)

for i := 0; i < len(nodes); i++ {
nodes[i].Close()
2 changes: 1 addition & 1 deletion integrationTests/testHeartbeatNode.go
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ import (

const (
defaultNodeName = "heartbeatNode"
timeBetweenPeerAuths = 15 * time.Second
timeBetweenPeerAuths = 10 * time.Second
timeBetweenHeartbeats = 5 * time.Second
timeBetweenSendsWhenError = time.Second
thresholdBetweenSends = 0.2