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
2d04fbb6
Commit
2d04fbb6
authored
Sep 29, 2020
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
add health tracker test
parent
9fba3e43
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
network/health/tracker_test.go
+62
-15
62 additions, 15 deletions
network/health/tracker_test.go
with
62 additions
and
15 deletions
network/health/tracker_test.go
+
62
−
15
View file @
2d04fbb6
...
...
@@ -7,37 +7,84 @@
package
health
import
(
"gitlab.com/elixxir/comms/network"
// "gitlab.com/elixxir/comms/network"
"testing"
"time"
)
// Happy path smoke test
func
TestNewTracker
(
t
*
testing
.
T
)
{
tracker
:=
newTracker
(
1
*
time
.
Second
)
//hbChan := tracker.heartbeat
// Initialize required variables
timeout
:=
500
*
time
.
Millisecond
tracker
:=
newTracker
(
timeout
)
counter
:=
0
positiveHb
:=
network
.
Heartbeat
{
HasWaitingRound
:
true
,
IsRoundComplete
:
true
,
}
// positiveHb := network.Heartbeat{
// HasWaitingRound: true,
// IsRoundComplete: true,
// }
// negativeHb := network.Heartbeat{
// HasWaitingRound: false,
// IsRoundComplete: false,
// }
listenChan
:=
make
(
chan
bool
)
// Build listening channel and listening function
listenChan
:=
make
(
chan
bool
,
10
)
listenFunc
:=
func
(
isHealthy
bool
)
{
if
isHealthy
{
counter
++
}
else
{
counter
--
}
}
tracker
.
AddChannel
(
listenChan
)
tracker
.
AddFunc
(
listenFunc
)
go
func
()
{
for
range
listenChan
{
for
isHealthy
:=
range
listenChan
{
if
isHealthy
{
counter
++
}
else
{
counter
--
}
}
}()
// Begin the health tracker
quit
:=
make
(
chan
struct
{})
go
tracker
.
start
(
quit
)
// Send a positive health heartbeat
expectedCount
:=
2
tracker
.
heartbeat
<-
positiveHb
// Wait for the heartbeat to register
for
i
:=
0
;
i
<
5
;
i
++
{
if
tracker
.
IsHealthy
()
&&
counter
==
expectedCount
{
break
}
else
{
time
.
Sleep
(
50
*
time
.
Millisecond
)
}
}
// Verify the network was marked as healthy
if
!
tracker
.
IsHealthy
()
{
t
.
Errorf
(
"Tracker did not become healthy"
)
return
}
// Verify the heartbeat triggered the listening chan/func
if
counter
!=
expectedCount
{
t
.
Errorf
(
"Expected counter to be %d, got %d"
,
expectedCount
,
counter
)
}
// Wait out the timeout
expectedCount
=
0
time
.
Sleep
(
timeout
)
// Verify the network was marked as NOT healthy
if
tracker
.
IsHealthy
()
{
t
.
Errorf
(
"Tracker should not report healthy"
)
return
}
// Verify the timeout triggered the listening chan/func
if
counter
!=
expectedCount
{
t
.
Errorf
(
"Expected counter to be %d, got %d"
,
expectedCount
,
counter
)
}
}
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