Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
931e58ae
Commit
931e58ae
authored
Aug 31, 2021
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added some testing
parent
40a3af9c
No related branches found
No related tags found
3 merge requests
!53
Release
,
!24
Lesure/offline nodes
,
!15
prevent hostpool from adding stale nodes
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
network/gateway/hostPool.go
+2
-1
2 additions, 1 deletion
network/gateway/hostPool.go
network/gateway/hostpool_test.go
+21
-5
21 additions, 5 deletions
network/gateway/hostpool_test.go
network/gateway/utils_test.go
+12
-0
12 additions, 0 deletions
network/gateway/utils_test.go
with
35 additions
and
6 deletions
network/gateway/hostPool.go
+
2
−
1
View file @
931e58ae
...
@@ -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
}
}
...
...
This diff is collapsed.
Click to expand it.
network/gateway/hostpool_test.go
+
21
−
5
View file @
931e58ae
...
@@ -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
}
}
}
...
...
This diff is collapsed.
Click to expand it.
network/gateway/utils_test.go
+
12
−
0
View file @
931e58ae
...
@@ -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
,
}},
}},
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment