-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/datastore: add an option to disable retries on RWTs
- Loading branch information
Showing
12 changed files
with
141 additions
and
12 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,56 @@ | ||
package test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/authzed/spicedb/pkg/datastore" | ||
"github.com/authzed/spicedb/pkg/datastore/options" | ||
) | ||
|
||
func RetryTest(t *testing.T, tester DatastoreTester) { | ||
disableRetriesOptions := []options.RWTOptionsOption{options.WithDisableRetries(true)} | ||
|
||
testCases := []struct { | ||
name string | ||
returnRetryableError bool | ||
txOptions []options.RWTOptionsOption | ||
countAssertion func(require.TestingT, interface{}, ...interface{}) | ||
}{ | ||
{"retryable with retries", true, nil, require.Positive}, | ||
{"non-retryable with retries", false, nil, require.Zero}, | ||
{"retryable retries disabled", true, disableRetriesOptions, require.Zero}, | ||
{"non-retryable retries disabled", false, disableRetriesOptions, require.Zero}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
require := require.New(t) | ||
|
||
rawDS, err := tester.New(0, veryLargeGCInterval, veryLargeGCWindow, 1) | ||
require.NoError(err) | ||
|
||
ds := rawDS.(TestableDatastore) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) | ||
defer cancel() | ||
|
||
var attempts int | ||
_, err = ds.ReadWriteTx(ctx, func(rwt datastore.ReadWriteTransaction) error { | ||
attempts++ | ||
|
||
if tc.returnRetryableError { | ||
return ds.ExampleRetryableError() | ||
} | ||
return errors.New("not retryable") | ||
}, tc.txOptions...) | ||
require.Error(err) | ||
retries := attempts - 1 | ||
tc.countAssertion(t, retries) | ||
}) | ||
} | ||
} |