diff --git a/network/instance.go b/network/instance.go index 0115b42007912463e4d3ab39fe1e5c4247e9b3c9..4ab3281a3d88e5bddd8e48f54a3d781fa29647bb 100644 --- a/network/instance.go +++ b/network/instance.go @@ -59,7 +59,7 @@ type Heartbeat struct { isRoundComplete bool } -// Register AddNode channel with Instance +// Register NetworkHealth channel with Instance func (i *Instance) SetNetworkHealthChan(c chan Heartbeat) { i.networkHealth = c } diff --git a/network/instance_test.go b/network/instance_test.go index e82f3df698c320f39f8a6713cd32273baae7f7e3..02a4cd03ee0849225c70a50c644fa88e67b54c9e 100644 --- a/network/instance_test.go +++ b/network/instance_test.go @@ -12,6 +12,7 @@ import ( ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/comms/testkeys" "gitlab.com/elixxir/comms/testutils" + "gitlab.com/elixxir/primitives/states" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/crypto/signature" "gitlab.com/xx_network/crypto/signature/rsa" @@ -710,6 +711,51 @@ func TestInstance_NodeEventModel(t *testing.T) { } } +// Happy path +func TestInstance_RoundUpdates(t *testing.T) { + i, _ := setupComm(t) + nwHealth := make(chan Heartbeat, 10) + i.SetNetworkHealthChan(nwHealth) + + // Build a basic RoundInfo object and sign it + privKey, err := rsa.LoadPrivateKeyFromPem(testkeys.LoadFromPath(testkeys.GetNodeKeyPath())) + if err != nil { + t.Errorf("Could not get rsa key: %s", err) + } + r := &mixmessages.RoundInfo{ + ID: 2, + UpdateID: 4, + State: uint32(states.COMPLETED), + } + err = signature.Sign(r, privKey) + if err != nil { + t.Errorf(err.Error()) + } + + // Set up a function to read channel output + isFinished := false + go func() { + for heartbeat := range nwHealth { + if !heartbeat.isRoundComplete { + t.Errorf("Round should have been complete") + } + if heartbeat.hasWaitingRound { + t.Errorf("Should have had no waiting rounds") + } + isFinished = true + break + } + }() + + // Send the round update + err = i.RoundUpdates([]*mixmessages.RoundInfo{r}) + + // Wait for other thread to finish + for !isFinished { + time.Sleep(50 * time.Millisecond) + } +} + // Happy path func TestInstance_UpdateGroup(t *testing.T) { i, f := setupComm(t) @@ -785,7 +831,7 @@ func TestInstance_RoundUpdateAddsToERS(t *testing.T) { privKey, err := rsa.LoadPrivateKeyFromPem(priv) pub := testkeys.LoadFromPath(testkeys.GetNodeCertPath()) if err != nil { - t.Errorf("Could not generate rsa key: %s", err) + t.Errorf("Could not get rsa key: %s", err) } // Create a basic testing NDF and sign it