1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

The variable heartbeat might be 0

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>

perfect the test case for 'discoveryOpts'

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
This commit is contained in:
Yanqiang Miao 2017-03-11 16:03:22 +08:00
parent 8b02a15d52
commit fb2bc35210
2 changed files with 9 additions and 2 deletions

View file

@ -81,8 +81,7 @@ func discoveryOpts(clusterOpts map[string]string) (time.Duration, time.Duration,
ttl = time.Duration(t) * time.Second
if _, ok := clusterOpts["discovery.heartbeat"]; !ok {
h := int(t / defaultDiscoveryTTLFactor)
heartbeat = time.Duration(h) * time.Second
heartbeat = time.Duration(t) * time.Second / time.Duration(defaultDiscoveryTTLFactor)
}
if ttl <= heartbeat {

View file

@ -1,6 +1,7 @@
package discovery
import (
"fmt"
"testing"
"time"
)
@ -86,6 +87,13 @@ func TestDiscoveryOpts(t *testing.T) {
t.Fatalf("Heartbeat - Expected : %v, Actual : %v", expected, heartbeat)
}
discaveryTTL := fmt.Sprintf("%d", defaultDiscoveryTTLFactor-1)
clusterOpts = map[string]string{"discovery.ttl": discaveryTTL}
heartbeat, ttl, err = discoveryOpts(clusterOpts)
if err == nil && heartbeat == 0 {
t.Fatal("discovery.heartbeat must be positive")
}
clusterOpts = map[string]string{}
heartbeat, ttl, err = discoveryOpts(clusterOpts)
if err != nil {