Address review comments.

Signed-off-by: Dong Chen <dongluo.chen@docker.com>
This commit is contained in:
Dong Chen 2016-01-11 16:08:51 -08:00
parent cf664141b6
commit 8f384b1d40
3 changed files with 5 additions and 5 deletions

View File

@ -212,13 +212,13 @@ func (e *Engine) IsHealthy() bool {
// HealthIndicator returns degree of healthiness between 0 and 100. // HealthIndicator returns degree of healthiness between 0 and 100.
// 0 means node is not healthy (unhealthy, pending), 100 means last connectivity was successful // 0 means node is not healthy (unhealthy, pending), 100 means last connectivity was successful
// other values indicate recent failures but haven't moved engine out of healthy state // other values indicate recent failures but haven't moved engine out of healthy state
func (e *Engine) HealthIndicator() int { func (e *Engine) HealthIndicator() int64 {
e.RLock() e.RLock()
e.RUnlock() defer e.RUnlock()
if e.state != stateHealthy || e.failureCount >= e.opts.FailureRetry { if e.state != stateHealthy || e.failureCount >= e.opts.FailureRetry {
return 0 return 0
} }
return 100 - e.failureCount*100/e.opts.FailureRetry return int64(100 - e.failureCount*100/e.opts.FailureRetry)
} }
// setState sets engine state // setState sets engine state

View File

@ -93,7 +93,7 @@ func TestHealthINdicator(t *testing.T) {
engine.setState(stateHealthy) engine.setState(stateHealthy)
assert.True(t, engine.HealthIndicator() == 100) assert.True(t, engine.HealthIndicator() == 100)
engine.incFailureCount() engine.incFailureCount()
assert.True(t, engine.HealthIndicator() == 100-100/engine.opts.FailureRetry) assert.True(t, engine.HealthIndicator() == (int64)(100-100/engine.opts.FailureRetry))
} }
func TestEngineConnectionFailure(t *testing.T) { func TestEngineConnectionFailure(t *testing.T) {

View File

@ -38,7 +38,7 @@ func NewNode(e *cluster.Engine) *Node {
UsedCpus: e.UsedCpus(), UsedCpus: e.UsedCpus(),
TotalMemory: e.TotalMemory(), TotalMemory: e.TotalMemory(),
TotalCpus: e.TotalCpus(), TotalCpus: e.TotalCpus(),
HealthIndicator: int64(e.HealthIndicator()), HealthIndicator: e.HealthIndicator(),
} }
} }