-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
652 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package helpers | ||
|
||
import "time" | ||
|
||
func NewStop(e error) *StopErr { | ||
return &StopErr{e} | ||
} | ||
|
||
type StopErr struct { | ||
Err error | ||
} | ||
|
||
func (s *StopErr) Error() string { | ||
return s.Err.Error() | ||
} | ||
|
||
func Retry(timeout time.Duration, sleep time.Duration, fn func() error) error { | ||
if err := fn(); err != nil { | ||
// allow early exit | ||
if v, ok := err.(*StopErr); ok { | ||
return v.Err | ||
} | ||
if timeout > 0 { | ||
time.Sleep(sleep) | ||
return Retry(timeout-sleep, sleep, fn) | ||
} | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestRetryTimeout(t *testing.T) { | ||
start := time.Now() | ||
_ = Retry(5*time.Second, 1*time.Second, func() error { | ||
return fmt.Errorf("test") | ||
}) | ||
stop := time.Now().Sub(start) | ||
if stop < 5*time.Second { | ||
t.Errorf("retry ended too soon: %v", stop) | ||
} | ||
} | ||
func TestRetryStopErr(t *testing.T) { | ||
start := time.Now() | ||
_ = Retry(5*time.Second, 1*time.Second, func() error { | ||
return NewStop(fmt.Errorf("test")) | ||
}) | ||
stop := time.Now().Sub(start) | ||
if stop > 1*time.Second { | ||
t.Errorf("retry with stop should not take so long: %v", stop) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
pkg/resourcemanager/azuresql/azuresqlshared/resourceclient.go
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.