set 1ms as container duration minimum value

Signed-off-by: Dong Chen <dongluo.chen@docker.com>
Upstream-commit: d8b6a35d0272d9bb121dda7d0bc53d0e53d8bd22
Component: engine
This commit is contained in:
Dong Chen
2017-04-12 15:45:29 -07:00
parent 47f6ff572e
commit 2f0c087a4c
7 changed files with 72 additions and 28 deletions
@@ -497,7 +497,7 @@ func cmd(b *Builder, args []string, attributes map[string]bool, original string)
}
// parseOptInterval(flag) is the duration of flag.Value, or 0 if
// empty. An error is reported if the value is given and less than 1 second.
// empty. An error is reported if the value is given and less than minimum duration.
func parseOptInterval(f *Flag) (time.Duration, error) {
s := f.Value
if s == "" {
@@ -507,8 +507,8 @@ func parseOptInterval(f *Flag) (time.Duration, error) {
if err != nil {
return 0, err
}
if d < time.Duration(time.Second) {
return 0, fmt.Errorf("Interval %#v cannot be less than 1 second", f.name)
if d < time.Duration(container.MinimumDuration) {
return 0, fmt.Errorf("Interval %#v cannot be less than %s", f.name, container.MinimumDuration)
}
return d, nil
}
@@ -530,3 +530,21 @@ func TestShell(t *testing.T) {
t.Fatalf("Shell should be set to %s, got %s", expectedShell, b.runConfig.Shell)
}
}
func TestParseOptInterval(t *testing.T) {
flInterval := &Flag{
name: "interval",
flagType: stringType,
Value: "50ns",
}
_, err := parseOptInterval(flInterval)
if err == nil {
t.Fatalf("Error should be presented for interval %s", flInterval.Value)
}
flInterval.Value = "1ms"
_, err = parseOptInterval(flInterval)
if err != nil {
t.Fatalf("Unexpected error: %s", err.Error())
}
}