Skip to content
Snippets Groups Projects
Commit 9ab731a9 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'XX-3134/GwHostPoolTest' into 'XX-3134/GwHostPool'

Resolve XX-3134 "/gwhostpooltest"

See merge request !569
parents 88f41d14 db1a9f0d
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ require ( ...@@ -6,7 +6,7 @@ require (
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/protobuf v1.4.3 github.com/golang/protobuf v1.4.3
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
github.com/liyue201/goqr v0.0.0-20200803022322-df443203d4ea // indirect github.com/liyue201/goqr v0.0.0-20200803022322-df443203d4ea
github.com/magiconair/properties v1.8.4 // indirect github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.4.0 // indirect github.com/mitchellh/mapstructure v1.4.0 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect github.com/pelletier/go-toml v1.8.1 // indirect
...@@ -23,7 +23,7 @@ require ( ...@@ -23,7 +23,7 @@ require (
gitlab.com/elixxir/crypto v0.0.7-0.20210319231554-b73b6e62ddbc gitlab.com/elixxir/crypto v0.0.7-0.20210319231554-b73b6e62ddbc
gitlab.com/elixxir/ekv v0.1.4 gitlab.com/elixxir/ekv v0.1.4
gitlab.com/elixxir/primitives v0.0.3-0.20210309193003-ef42ebb4800b gitlab.com/elixxir/primitives v0.0.3-0.20210309193003-ef42ebb4800b
gitlab.com/xx_network/comms v0.0.4-0.20210323205910-f01316c830dd gitlab.com/xx_network/comms v0.0.4-0.20210331153942-daf17c8b6b47
gitlab.com/xx_network/crypto v0.0.5-0.20210319231335-249c6b1aa323 gitlab.com/xx_network/crypto v0.0.5-0.20210319231335-249c6b1aa323
gitlab.com/xx_network/primitives v0.0.4-0.20210309173740-eb8cd411334a gitlab.com/xx_network/primitives v0.0.4-0.20210309173740-eb8cd411334a
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
......
...@@ -292,6 +292,12 @@ gitlab.com/xx_network/comms v0.0.4-0.20210323140408-2b2613abb5a3 h1:Mh+YiOX89vG9 ...@@ -292,6 +292,12 @@ gitlab.com/xx_network/comms v0.0.4-0.20210323140408-2b2613abb5a3 h1:Mh+YiOX89vG9
gitlab.com/xx_network/comms v0.0.4-0.20210323140408-2b2613abb5a3/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI= gitlab.com/xx_network/comms v0.0.4-0.20210323140408-2b2613abb5a3/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI=
gitlab.com/xx_network/comms v0.0.4-0.20210323205910-f01316c830dd h1:WZn6y52gqigTXBAdsDRM3KWNBwnPEnYoGcBrsSAuphI= gitlab.com/xx_network/comms v0.0.4-0.20210323205910-f01316c830dd h1:WZn6y52gqigTXBAdsDRM3KWNBwnPEnYoGcBrsSAuphI=
gitlab.com/xx_network/comms v0.0.4-0.20210323205910-f01316c830dd/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI= gitlab.com/xx_network/comms v0.0.4-0.20210323205910-f01316c830dd/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI=
gitlab.com/xx_network/comms v0.0.4-0.20210329190058-55f9bdf16249 h1:dDcesEGcAzN1C6PP7Y8T0Ky5c4mpRfhVFMZJKBrbQzk=
gitlab.com/xx_network/comms v0.0.4-0.20210329190058-55f9bdf16249/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI=
gitlab.com/xx_network/comms v0.0.4-0.20210330224545-2d0e07fb64c6 h1:LsxlArrT5mIM5rRbMuNp+PQPWrCbPKhunHO2MfznbsE=
gitlab.com/xx_network/comms v0.0.4-0.20210330224545-2d0e07fb64c6/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI=
gitlab.com/xx_network/comms v0.0.4-0.20210331153942-daf17c8b6b47 h1:r8qBdMtuQouVylWl5RPctlXzPldcbhI2bvYkeUB1Ia0=
gitlab.com/xx_network/comms v0.0.4-0.20210331153942-daf17c8b6b47/go.mod h1:0Hx+zO3Pr4uYw4RZXFnPM3ocjY6bPIKDiHCjWTZLOSI=
gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE= gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE=
gitlab.com/xx_network/crypto v0.0.4 h1:lpKOL5mTJ2awWMfgBy30oD/UvJVrWZzUimSHlOdZZxo= gitlab.com/xx_network/crypto v0.0.4 h1:lpKOL5mTJ2awWMfgBy30oD/UvJVrWZzUimSHlOdZZxo=
gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk= gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk=
......
...@@ -115,7 +115,6 @@ func (h *HostPool) GetAny(length int) []*connect.Host { ...@@ -115,7 +115,6 @@ func (h *HostPool) GetAny(length int) []*connect.Host {
length = int(h.poolParams.poolSize) length = int(h.poolParams.poolSize)
} }
result := make([]*connect.Host, length) result := make([]*connect.Host, length)
h.hostMux.RLock() h.hostMux.RLock()
for i := 0; i < length; { for i := 0; i < length; {
gwIdx := readRangeUint32(0, h.poolParams.poolSize, h.rng) gwIdx := readRangeUint32(0, h.poolParams.poolSize, h.rng)
...@@ -212,9 +211,8 @@ func (h *HostPool) pruneHostPool() error { ...@@ -212,9 +211,8 @@ func (h *HostPool) pruneHostPool() error {
for poolIdx := uint32(0); poolIdx < h.poolParams.poolSize; { for poolIdx := uint32(0); poolIdx < h.poolParams.poolSize; {
host := h.hostList[poolIdx] host := h.hostList[poolIdx]
// Check the Host for errors // Check the Host for errors
if host == nil || *host.GetMetrics().ErrCounter >= h.poolParams.errThreshold { if host == nil || host.GetMetrics().GetErrorCounter() >= h.poolParams.errThreshold {
// If errors occurred, randomly select a new Gw by index in the NDF // If errors occurred, randomly select a new Gw by index in the NDF
ndfIdx := readRangeUint32(0, uint32(len(h.ndf.Gateways)), h.rng) ndfIdx := readRangeUint32(0, uint32(len(h.ndf.Gateways)), h.rng)
...@@ -227,6 +225,7 @@ func (h *HostPool) pruneHostPool() error { ...@@ -227,6 +225,7 @@ func (h *HostPool) pruneHostPool() error {
// Verify the GwId is not already in the hostMap // Verify the GwId is not already in the hostMap
if _, ok := h.hostMap[*gwId]; !ok { if _, ok := h.hostMap[*gwId]; !ok {
// If it is a new GwId, replace the old Host with the new Host // If it is a new GwId, replace the old Host with the new Host
err = h.replaceHost(gwId, poolIdx) err = h.replaceHost(gwId, poolIdx)
if err != nil { if err != nil {
......
This diff is collapsed.
package gateway
import (
"gitlab.com/xx_network/comms/connect"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
)
// Mock structure adhering to HostManager to be used for happy path
type mockManager struct {
hosts map[string]*connect.Host
}
// Constructor for mockManager
func newMockManager() *mockManager {
return &mockManager{
hosts: make(map[string]*connect.Host),
}
}
func (mhp *mockManager) GetHost(hostId *id.ID) (*connect.Host, bool) {
h, ok := mhp.hosts[hostId.String()]
return h, ok
}
func (mhp *mockManager) AddHost(hid *id.ID, address string,
cert []byte, params connect.HostParams) (host *connect.Host, err error) {
host, err = connect.NewHost(hid, address, cert, params)
if err != nil {
return nil, err
}
mhp.hosts[hid.String()] = host
return
}
func (mhp *mockManager) RemoveHost(hid *id.ID) {
delete(mhp.hosts, hid.String())
}
// Returns a mock
func getTestNdf(face interface{}) *ndf.NetworkDefinition {
return &ndf.NetworkDefinition{
Gateways: []ndf.Gateway{{
ID: id.NewIdFromUInt(0, id.Gateway, face)[:],
Address: "0.0.0.1",
}, {
ID: id.NewIdFromUInt(1, id.Gateway, face)[:],
Address: "0.0.0.2",
}, {
ID: id.NewIdFromUInt(2, id.Gateway, face)[:],
Address: "0.0.0.3",
}, {
ID: id.NewIdFromUInt(3, id.Gateway, face)[:],
Address: "0.0.0.1",
}, {
ID: id.NewIdFromUInt(4, id.Gateway, face)[:],
Address: "0.0.0.2",
}, {
ID: id.NewIdFromUInt(5, id.Gateway, face)[:],
Address: "0.0.0.3",
}, {
ID: id.NewIdFromUInt(6, id.Gateway, face)[:],
Address: "0.0.0.1",
}, {
ID: id.NewIdFromUInt(7, id.Gateway, face)[:],
Address: "0.0.0.2",
}, {
ID: id.NewIdFromUInt(8, id.Gateway, face)[:],
Address: "0.0.0.3",
}, {
ID: id.NewIdFromUInt(9, id.Gateway, face)[:],
Address: "0.0.0.1",
}, {
ID: id.NewIdFromUInt(10, id.Gateway, face)[:],
Address: "0.0.0.2",
}, {
ID: id.NewIdFromUInt(11, id.Gateway, face)[:],
Address: "0.0.0.3",
}},
Nodes: []ndf.Node{{
ID: id.NewIdFromUInt(0, id.Node, face)[:],
Address: "0.0.0.1",
}, {
ID: id.NewIdFromUInt(1, id.Node, face)[:],
Address: "0.0.0.2",
}, {
ID: id.NewIdFromUInt(2, id.Node, face)[:],
Address: "0.0.0.3",
}, {
ID: id.NewIdFromUInt(3, id.Node, face)[:],
Address: "0.0.0.1",
}, {
ID: id.NewIdFromUInt(4, id.Node, face)[:],
Address: "0.0.0.2",
}, {
ID: id.NewIdFromUInt(5, id.Node, face)[:],
Address: "0.0.0.3",
}, {
ID: id.NewIdFromUInt(6, id.Node, face)[:],
Address: "0.0.0.1",
}, {
ID: id.NewIdFromUInt(7, id.Node, face)[:],
Address: "0.0.0.2",
}, {
ID: id.NewIdFromUInt(8, id.Node, face)[:],
Address: "0.0.0.3",
}, {
ID: id.NewIdFromUInt(9, id.Node, face)[:],
Address: "0.0.0.1",
}, {
ID: id.NewIdFromUInt(10, id.Node, face)[:],
Address: "0.0.0.2",
}, {
ID: id.NewIdFromUInt(11, id.Node, face)[:],
Address: "0.0.0.3",
}},
}
}
...@@ -39,6 +39,7 @@ const ReturningGateway = "GetMessageRequest" ...@@ -39,6 +39,7 @@ const ReturningGateway = "GetMessageRequest"
const FalsePositive = "FalsePositive" const FalsePositive = "FalsePositive"
const PayloadMessage = "Payload" const PayloadMessage = "Payload"
const ErrorGateway = "Error" const ErrorGateway = "Error"
type mockMessageRetrievalComms struct { type mockMessageRetrievalComms struct {
testingSignature *testing.T testingSignature *testing.T
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment