-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor retry functinoality into a separate package
- Loading branch information
Showing
22 changed files
with
349 additions
and
309 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ func TestAliasIntegrationSuite(t *testing.T) { | |
func (s *AliasIntegrationSuite) TestGetAlias() { | ||
ctx := test.Context() | ||
|
||
alias, err := s.rc.GetAlias(ctx, persistentWorkspace, persistentAlias) | ||
alias, err := s.rc.GetAlias(ctx, test.PersistentWorkspace, test.PersistentAlias) | ||
require.NoError(s.T(), err) | ||
assert.Equal(s.T(), "[email protected]", alias.GetCreatorEmail()) | ||
} | ||
|
@@ -45,7 +45,7 @@ func (s *AliasIntegrationSuite) TestListAliases() { | |
func (s *AliasIntegrationSuite) TestListAliasesForWorkspace() { | ||
ctx := test.Context() | ||
|
||
aliases, err := s.rc.ListAliases(ctx, option.WithAliasWorkspace(persistentWorkspace)) | ||
aliases, err := s.rc.ListAliases(ctx, option.WithAliasWorkspace(test.PersistentWorkspace)) | ||
require.NoError(s.T(), err) | ||
for _, a := range aliases { | ||
s.T().Logf("workspace: %s", a.GetName()) | ||
|
@@ -55,17 +55,17 @@ func (s *AliasIntegrationSuite) TestListAliasesForWorkspace() { | |
func (s *AliasIntegrationSuite) TestAliases() { | ||
ctx := test.Context() | ||
|
||
_, err := s.rc.CreateAlias(ctx, persistentWorkspace, s.alias, []string{"commons._events"}) | ||
_, err := s.rc.CreateAlias(ctx, test.PersistentWorkspace, s.alias, []string{"commons._events"}) | ||
require.NoError(s.T(), err) | ||
|
||
err = s.rc.WaitUntilAliasAvailable(ctx, persistentWorkspace, s.alias) | ||
err = s.rc.WaitUntilAliasAvailable(ctx, test.PersistentWorkspace, s.alias) | ||
require.NoError(s.T(), err) | ||
|
||
// update | ||
|
||
err = s.rc.WaitUntilAliasAvailable(ctx, persistentWorkspace, s.alias) | ||
err = s.rc.WaitUntilAliasAvailable(ctx, test.PersistentWorkspace, s.alias) | ||
require.NoError(s.T(), err) | ||
|
||
err = s.rc.DeleteAlias(ctx, persistentWorkspace, s.alias) | ||
err = s.rc.DeleteAlias(ctx, test.PersistentWorkspace, s.alias) | ||
require.NoError(s.T(), err) | ||
} |
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
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,37 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/rockset/rockset-go-client/retry" | ||
) | ||
|
||
// Retrier is used for testing | ||
type Retrier struct{} | ||
|
||
func (t Retrier) Retry(ctx context.Context, retryFn retry.Func) error { | ||
for { | ||
err := retryFn() | ||
if err == nil { | ||
return nil | ||
} | ||
if !retry.DefaultRetryableErrorCheck(err) { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
func (t Retrier) RetryWithCheck(ctx context.Context, checkFunc retry.CheckFn) error { | ||
for { | ||
r, err := checkFunc() | ||
if err == nil { | ||
return nil | ||
} | ||
if !r { | ||
return nil | ||
} | ||
if !retry.DefaultRetryableErrorCheck(err) { | ||
return err | ||
} | ||
} | ||
} |
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,54 @@ | ||
package test | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"strings" | ||
"time" | ||
) | ||
|
||
// these are used for testing when a persistent value is needed | ||
const buildNum = "CIRCLE_BUILD_NUM" | ||
const PersistentWorkspace = "persistent" | ||
const PersistentCollection = "snp" | ||
const PersistentAlias = "getalias" | ||
|
||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
|
||
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano())) | ||
|
||
// StringWithCharset creates a random string with length and charset | ||
func stringWithCharset(length int, charset string) string { | ||
b := make([]byte, length) | ||
for i := range b { | ||
b[i] = charset[seededRand.Intn(len(charset))] | ||
} | ||
return string(b) | ||
} | ||
|
||
// RandomString creates a random string with a specific length | ||
func RandomString(length int) string { | ||
return stringWithCharset(length, charset) | ||
} | ||
|
||
func RandomName(prefix string) string { | ||
num, found := os.LookupEnv(buildNum) | ||
if !found { | ||
if user, found := os.LookupEnv("USER"); found { | ||
num = strings.ToLower(user) | ||
} else { | ||
num = "dev" | ||
} | ||
} | ||
|
||
return fmt.Sprintf("go_%s_%s_%s", num, prefix, RandomString(6)) | ||
} | ||
|
||
func Description() string { | ||
num, found := os.LookupEnv(buildNum) | ||
if !found { | ||
num = "dev" | ||
} | ||
return fmt.Sprintf("created by terraform integration test run %s", num) | ||
} |
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
Oops, something went wrong.