Merge pull request #8928 from gyuho/timeout-config

embed: error on zero heartbeat-interval, election-timeout
This commit is contained in:
Gyuho Lee 2017-11-28 11:11:20 -08:00 committed by GitHub
commit 6e116542c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -409,6 +409,12 @@ func (cfg *Config) Validate() error {
return ErrConflictBootstrapFlags
}
if cfg.TickMs <= 0 {
return fmt.Errorf("--heartbeat-interval must be >0 (set to %dms)", cfg.TickMs)
}
if cfg.ElectionMs <= 0 {
return fmt.Errorf("--election-timeout must be >0 (set to %dms)", cfg.ElectionMs)
}
if 5*cfg.TickMs > cfg.ElectionMs {
return fmt.Errorf("--election-timeout[%vms] should be at least as 5 times as --heartbeat-interval[%vms]", cfg.ElectionMs, cfg.TickMs)
}

View File

@ -460,8 +460,19 @@ func TestConfigFileElectionTimeout(t *testing.T) {
},
{
ElectionMs: 60000,
TickMs: 10000,
errStr: "is too long, and should be set less than",
},
{
ElectionMs: 100,
TickMs: 0,
errStr: "--heartbeat-interval must be >0 (set to 0ms)",
},
{
ElectionMs: 0,
TickMs: 100,
errStr: "--election-timeout must be >0 (set to 0ms)",
},
}
for i, tt := range tests {