Skip to content

Commit

Permalink
Add retry function to test utils (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
ray-milkey authored Jan 21, 2022
1 parent 9e92bc2 commit 7f30cf7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.6-dev
0.6.6
27 changes: 27 additions & 0 deletions pkg/utils/retry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020-present Open Networking Foundation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package utils

import "time"

func Retry(count int, delay time.Duration, check func() bool) bool {
for attempt := 1; attempt != count; attempt++ {
if check() {
return true
}
time.Sleep(delay)
}
return false
}

0 comments on commit 7f30cf7

Please sign in to comment.