mirror of https://github.com/status-im/consul.git
Makes the API behave better with small wait values.
This commit is contained in:
parent
49342dc973
commit
c048c5aca6
11
api/api.go
11
api/api.go
|
@ -261,9 +261,16 @@ func (r *request) setQueryOptions(q *QueryOptions) {
|
|||
}
|
||||
}
|
||||
|
||||
// durToMsec converts a duration to a millisecond specified string
|
||||
// durToMsec converts a duration to a millisecond specified string. If the
|
||||
// user selected a positive value that rounds to 0 ms, then we will use 1 ms
|
||||
// so they get a short delay, otherwise Consul will translate the 0 ms into
|
||||
// a huge default delay.
|
||||
func durToMsec(dur time.Duration) string {
|
||||
return fmt.Sprintf("%dms", dur/time.Millisecond)
|
||||
ms := dur / time.Millisecond
|
||||
if dur > 0 && ms == 0 {
|
||||
ms = 1
|
||||
}
|
||||
return fmt.Sprintf("%dms", ms)
|
||||
}
|
||||
|
||||
// setWriteOptions is used to annotate the request with
|
||||
|
|
|
@ -254,3 +254,21 @@ func TestAPI_UnixSocket(t *testing.T) {
|
|||
t.Fatalf("bad: %v", info)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPI_durToMsec(t *testing.T) {
|
||||
if ms := durToMsec(0); ms != "0ms" {
|
||||
t.Fatalf("bad: %s", ms)
|
||||
}
|
||||
|
||||
if ms := durToMsec(time.Millisecond); ms != "1ms" {
|
||||
t.Fatalf("bad: %s", ms)
|
||||
}
|
||||
|
||||
if ms := durToMsec(time.Microsecond); ms != "1ms" {
|
||||
t.Fatalf("bad: %s", ms)
|
||||
}
|
||||
|
||||
if ms := durToMsec(5 * time.Millisecond); ms != "5ms" {
|
||||
t.Fatalf("bad: %s", ms)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue