mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
Signed-off-by: Wei Liu <wei.liu@zilliz.com>
This commit is contained in:
parent
76b06abc29
commit
e2e2487f40
@ -53,6 +53,12 @@ func Do(ctx context.Context, fn func() error, opts ...Option) error {
|
||||
return el
|
||||
}
|
||||
|
||||
deadline, ok := ctx.Deadline()
|
||||
if ok && time.Until(deadline) < c.sleep {
|
||||
// to avoid sleep until ctx done
|
||||
return el
|
||||
}
|
||||
|
||||
select {
|
||||
case <-time.After(c.sleep):
|
||||
case <-ctx.Done():
|
||||
|
||||
@ -63,6 +63,12 @@ func TestMaxSleepTime(t *testing.T) {
|
||||
err := Do(ctx, testFn, Attempts(3), MaxSleepTime(200*time.Millisecond))
|
||||
assert.Error(t, err)
|
||||
t.Log(err)
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
||||
defer cancel()
|
||||
err = Do(ctx, testFn, Attempts(10), MaxSleepTime(200*time.Millisecond))
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, ctx.Err())
|
||||
}
|
||||
|
||||
func TestSleep(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user