Skip to content
Snippets Groups Projects
Commit 6287a8fa authored by Josh Brooks's avatar Josh Brooks
Browse files

Merge branch 'hotfix/HealthTracker' into 'Ursula/UD'

Add and implement WasHealthy() to HealthTracker

See merge request !484
parents e7377972 1298e0fc
No related branches found
No related tags found
No related merge requests found
......@@ -11,4 +11,5 @@ type HealthTracker interface {
AddChannel(chan bool)
AddFunc(f func(bool))
IsHealthy() bool
WasHealthy() bool
}
......@@ -28,7 +28,11 @@ type Tracker struct {
running bool
// Determines the current health status
isHealthy bool
// Denotes the past health status
// wasHealthy is true if isHealthy has ever been true
wasHealthy bool
mux sync.RWMutex
}
......@@ -79,8 +83,19 @@ func (t *Tracker) IsHealthy() bool {
return t.isHealthy
}
// Returns true if isHealthy has ever been true
func (t *Tracker) WasHealthy() bool {
t.mux.RLock()
defer t.mux.RUnlock()
return t.wasHealthy
}
func (t *Tracker) setHealth(h bool) {
t.mux.Lock()
// Only set wasHealthy to true if either
// wasHealthy is true or
// wasHealthy false but h value is true
t.wasHealthy = t.wasHealthy || h
t.isHealthy = h
t.mux.Unlock()
t.transmit(h)
......
......@@ -72,6 +72,12 @@ func TestNewTracker(t *testing.T) {
return
}
// Check if the tracker was ever healthy
if !tracker.WasHealthy() {
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)
......@@ -87,6 +93,13 @@ func TestNewTracker(t *testing.T) {
return
}
// Check if the tracker was ever healthy,
// after setting healthy to false
if !tracker.WasHealthy() {
t.Errorf("Tracker was healthy previously but not reported healthy")
return
}
// Verify the timeout triggered the listening chan/func
if counter != expectedCount {
t.Errorf("Expected counter to be %d, got %d", expectedCount, counter)
......
......@@ -48,10 +48,9 @@ type Manager struct {
// New manager builds a new user discovery manager. It requires that an
// updated NDF is available and will error if one is not.
func NewManager(client *api.Client) (*Manager, error) {
if !client.GetHealth().IsHealthy(){
if !client.GetHealth().WasHealthy() {
return nil, errors.New("cannot start UD Manager when network " +
"is not healthy")
"was never healthy")
}
m := &Manager{
......@@ -126,7 +125,3 @@ func (m *Manager) startProcesses() stoppable.Stoppable {
udMulti.Add(searchStop)
return lookupStop
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment