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 {