Skip to content
Snippets Groups Projects
Commit 931e58ae authored by Jake Taylor's avatar Jake Taylor
Browse files

added some testing

parent 40a3af9c
No related branches found
No related tags found
3 merge requests!53Release,!24Lesure/offline nodes,!15prevent hostpool from adding stale nodes
...@@ -323,8 +323,9 @@ func (h *HostPool) forceReplace(oldPoolIndex uint32) error { ...@@ -323,8 +323,9 @@ func (h *HostPool) forceReplace(oldPoolIndex uint32) error {
nodeId := gwId.DeepCopy() nodeId := gwId.DeepCopy()
nodeId.SetType(id.Node) nodeId.SetType(id.Node)
nodeNdfIdx := h.ndfMap[*nodeId] nodeNdfIdx := h.ndfMap[*nodeId]
isNodeStale := h.ndf.Nodes[nodeNdfIdx].Status != ndf.Stale isNodeStale := h.ndf.Nodes[nodeNdfIdx].Status == ndf.Stale
if isNodeStale { if isNodeStale {
jww.DEBUG.Printf("Ignoring stale node: %s", nodeId.String())
continue continue
} }
......
...@@ -9,6 +9,7 @@ package gateway ...@@ -9,6 +9,7 @@ package gateway
import ( import (
"fmt" "fmt"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage"
"gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/comms/network"
"gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/crypto/fastRNG"
...@@ -143,7 +144,7 @@ func TestHostPool_ManageHostPool(t *testing.T) { ...@@ -143,7 +144,7 @@ func TestHostPool_ManageHostPool(t *testing.T) {
// Construct nodes // Construct nodes
nodeId := gwId.DeepCopy() nodeId := gwId.DeepCopy()
nodeId.SetType(id.Node) nodeId.SetType(id.Node)
newNodes[i] = ndf.Node{ID: nodeId.Bytes()} newNodes[i] = ndf.Node{ID: nodeId.Bytes(), Status: ndf.Active}
} }
...@@ -315,9 +316,19 @@ func TestHostPool_ForceReplace(t *testing.T) { ...@@ -315,9 +316,19 @@ func TestHostPool_ForceReplace(t *testing.T) {
testStorage := storage.InitTestingSession(t) testStorage := storage.InitTestingSession(t)
addGwChan := make(chan network.NodeGateway) addGwChan := make(chan network.NodeGateway)
newGateway := ndf.Gateway{
ID: id.NewIdFromUInt(27, id.Gateway, t).Bytes(),
}
newNode := ndf.Node{
ID: id.NewIdFromUInt(27, id.Node, t).Bytes(),
Status: ndf.Stale,
}
testNdf.Gateways = append(testNdf.Gateways, newGateway)
testNdf.Nodes = append(testNdf.Nodes, newNode)
// Construct custom params // Construct custom params
params := DefaultPoolParams() params := DefaultPoolParams()
params.PoolSize = uint32(len(testNdf.Gateways)) params.PoolSize = uint32(len(testNdf.Gateways) - 1) // One of the nodes is set to stale
// Pull all gateways from ndf into host manager // Pull all gateways from ndf into host manager
for _, gw := range testNdf.Gateways { for _, gw := range testNdf.Gateways {
...@@ -343,13 +354,17 @@ func TestHostPool_ForceReplace(t *testing.T) { ...@@ -343,13 +354,17 @@ func TestHostPool_ForceReplace(t *testing.T) {
} }
// Add all gateways to hostPool's map // Add all gateways to hostPool's map
for index, gw := range testNdf.Gateways { for i := uint32(0); i < params.PoolSize; i++ {
gw := testNdf.Gateways[i]
if i == 0 {
continue
}
gwId, err := id.Unmarshal(gw.ID) gwId, err := id.Unmarshal(gw.ID)
if err != nil { if err != nil {
t.Fatalf("Failed to unmarshal ID in mock ndf: %v", err) t.Fatalf("Failed to unmarshal ID in mock ndf: %v", err)
} }
err = testPool.replaceHost(gwId, uint32(index)) err = testPool.replaceHost(gwId, i)
if err != nil { if err != nil {
t.Fatalf("Failed to replace host in set-up: %v", err) t.Fatalf("Failed to replace host in set-up: %v", err)
} }
...@@ -497,6 +512,7 @@ func TestHostPool_UpdateNdf(t *testing.T) { ...@@ -497,6 +512,7 @@ func TestHostPool_UpdateNdf(t *testing.T) {
// Full test // Full test
func TestHostPool_GetPreferred(t *testing.T) { func TestHostPool_GetPreferred(t *testing.T) {
jww.SetLogThreshold(jww.LevelTrace)
manager := newMockManager() manager := newMockManager()
rng := fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG) rng := fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG)
testNdf := getTestNdf(t) testNdf := getTestNdf(t)
...@@ -792,7 +808,7 @@ func TestHostPool_UpdateConns_RemoveGateways(t *testing.T) { ...@@ -792,7 +808,7 @@ func TestHostPool_UpdateConns_RemoveGateways(t *testing.T) {
// Construct nodes // Construct nodes
nodeId := gwId.DeepCopy() nodeId := gwId.DeepCopy()
nodeId.SetType(id.Node) nodeId.SetType(id.Node)
newNodes[i] = ndf.Node{ID: nodeId.Bytes()} newNodes[i] = ndf.Node{ID: nodeId.Bytes(), Status: ndf.Active}
} }
......
...@@ -90,39 +90,51 @@ func getTestNdf(face interface{}) *ndf.NetworkDefinition { ...@@ -90,39 +90,51 @@ func getTestNdf(face interface{}) *ndf.NetworkDefinition {
Nodes: []ndf.Node{{ Nodes: []ndf.Node{{
ID: id.NewIdFromUInt(0, id.Node, face)[:], ID: id.NewIdFromUInt(0, id.Node, face)[:],
Address: "0.0.0.1", Address: "0.0.0.1",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(1, id.Node, face)[:], ID: id.NewIdFromUInt(1, id.Node, face)[:],
Address: "0.0.0.2", Address: "0.0.0.2",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(2, id.Node, face)[:], ID: id.NewIdFromUInt(2, id.Node, face)[:],
Address: "0.0.0.3", Address: "0.0.0.3",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(3, id.Node, face)[:], ID: id.NewIdFromUInt(3, id.Node, face)[:],
Address: "0.0.0.1", Address: "0.0.0.1",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(4, id.Node, face)[:], ID: id.NewIdFromUInt(4, id.Node, face)[:],
Address: "0.0.0.2", Address: "0.0.0.2",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(5, id.Node, face)[:], ID: id.NewIdFromUInt(5, id.Node, face)[:],
Address: "0.0.0.3", Address: "0.0.0.3",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(6, id.Node, face)[:], ID: id.NewIdFromUInt(6, id.Node, face)[:],
Address: "0.0.0.1", Address: "0.0.0.1",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(7, id.Node, face)[:], ID: id.NewIdFromUInt(7, id.Node, face)[:],
Address: "0.0.0.2", Address: "0.0.0.2",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(8, id.Node, face)[:], ID: id.NewIdFromUInt(8, id.Node, face)[:],
Address: "0.0.0.3", Address: "0.0.0.3",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(9, id.Node, face)[:], ID: id.NewIdFromUInt(9, id.Node, face)[:],
Address: "0.0.0.1", Address: "0.0.0.1",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(10, id.Node, face)[:], ID: id.NewIdFromUInt(10, id.Node, face)[:],
Address: "0.0.0.2", Address: "0.0.0.2",
Status: ndf.Active,
}, { }, {
ID: id.NewIdFromUInt(11, id.Node, face)[:], ID: id.NewIdFromUInt(11, id.Node, face)[:],
Address: "0.0.0.3", Address: "0.0.0.3",
Status: ndf.Active,
}}, }},
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment