diff --git a/network/gateway/hostPool.go b/network/gateway/hostPool.go index 51f1c3a76141386865835978240a83e696588da3..2fea0e4b3e104402cda56051e100a365d53a0858 100644 --- a/network/gateway/hostPool.go +++ b/network/gateway/hostPool.go @@ -323,8 +323,9 @@ func (h *HostPool) forceReplace(oldPoolIndex uint32) error { nodeId := gwId.DeepCopy() nodeId.SetType(id.Node) nodeNdfIdx := h.ndfMap[*nodeId] - isNodeStale := h.ndf.Nodes[nodeNdfIdx].Status != ndf.Stale + isNodeStale := h.ndf.Nodes[nodeNdfIdx].Status == ndf.Stale if isNodeStale { + jww.DEBUG.Printf("Ignoring stale node: %s", nodeId.String()) continue } diff --git a/network/gateway/hostpool_test.go b/network/gateway/hostpool_test.go index e06d49dab9f88673e8a1fea3c4a364e7697c4190..15d1c43480915f46f1aab69baca39164c2c5a9bf 100644 --- a/network/gateway/hostpool_test.go +++ b/network/gateway/hostpool_test.go @@ -9,6 +9,7 @@ package gateway import ( "fmt" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/crypto/fastRNG" @@ -143,7 +144,7 @@ func TestHostPool_ManageHostPool(t *testing.T) { // Construct nodes nodeId := gwId.DeepCopy() 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) { testStorage := storage.InitTestingSession(t) 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 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 for _, gw := range testNdf.Gateways { @@ -343,13 +354,17 @@ func TestHostPool_ForceReplace(t *testing.T) { } // 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) if err != nil { 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 { t.Fatalf("Failed to replace host in set-up: %v", err) } @@ -497,6 +512,7 @@ func TestHostPool_UpdateNdf(t *testing.T) { // Full test func TestHostPool_GetPreferred(t *testing.T) { + jww.SetLogThreshold(jww.LevelTrace) manager := newMockManager() rng := fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG) testNdf := getTestNdf(t) @@ -792,7 +808,7 @@ func TestHostPool_UpdateConns_RemoveGateways(t *testing.T) { // Construct nodes nodeId := gwId.DeepCopy() nodeId.SetType(id.Node) - newNodes[i] = ndf.Node{ID: nodeId.Bytes()} + newNodes[i] = ndf.Node{ID: nodeId.Bytes(), Status: ndf.Active} } diff --git a/network/gateway/utils_test.go b/network/gateway/utils_test.go index 9f75ace1429e947ef7c8a399f3f088e2583777de..644e2440d8a3c3b9c459845081d0c0ac4f76e822 100644 --- a/network/gateway/utils_test.go +++ b/network/gateway/utils_test.go @@ -90,39 +90,51 @@ func getTestNdf(face interface{}) *ndf.NetworkDefinition { Nodes: []ndf.Node{{ ID: id.NewIdFromUInt(0, id.Node, face)[:], Address: "0.0.0.1", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(1, id.Node, face)[:], Address: "0.0.0.2", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(2, id.Node, face)[:], Address: "0.0.0.3", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(3, id.Node, face)[:], Address: "0.0.0.1", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(4, id.Node, face)[:], Address: "0.0.0.2", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(5, id.Node, face)[:], Address: "0.0.0.3", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(6, id.Node, face)[:], Address: "0.0.0.1", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(7, id.Node, face)[:], Address: "0.0.0.2", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(8, id.Node, face)[:], Address: "0.0.0.3", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(9, id.Node, face)[:], Address: "0.0.0.1", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(10, id.Node, face)[:], Address: "0.0.0.2", + Status: ndf.Active, }, { ID: id.NewIdFromUInt(11, id.Node, face)[:], Address: "0.0.0.3", + Status: ndf.Active, }}, } }