-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring API client Waiters for better refactored API Client #442
Comments
Should waiter options expose a way for the application to modify or change the modeled waiter's wait state? This option would be in addition to the other wait options like max attempts, delay, etc. In this proposal,
client := s3.NewFromConfig(cfg)
waiter := s3.NewHeadBucketWaiter(client)
err := waiter.WaitForBucketExists(context.TODO(), &s3.HeadBucketInput{
Bucket: aws.String("example"),
}, func(o *s3.HeadBucketWaiterOptions) {
baseCheck := o.WaitCheck
o.WaitCheck = func(ctx context.Context, result *s3.HeadBucketOutput) (bool, error) {
// Some custom wait check, that delegates to the SDK's check if not succeeded
if resp := awshttp.GetRawResponse(result.ResultMetadata); resp != nil && resp.StatusCode == 404 {
return true, nil // continue waiting
}
return baseCheck(ctx, result)
}
}) |
Fixed in aws/smithy-go#237, but API models wait waiters have not yet been added to the v2 SDK. |
Closing this and can track model update in #989 |
|
This issue details how the v2 AWS SDK for Go's API client waiters need to be updated based on the API client refactor proposed in #438.
Proposal #438 would remove the,
WaitUntil
methods from the API clients, and added as function's to the API client's package. The waiters are higher level functionality provided by the SDK that build on the API to add novel functionality. Such as waiting for a Amazon S3 bucket to exist.Proposed API Client Waiter Refactor
The proposed refactor of the SDK's clients is split into four parts, API Client, Paginators, Waiters, and Request Presigner helpers. This proposal covers the API client waiter changes. Similar to paginators, waiters are higher-level functionality that build on top of the service's API.
The following example demonstrates an application creating a waiter to wait for a specific S3 object to exist.
The
WaitUntilObjectExists
function is called with an API client for theHeadObject
operation. The waiter blocks until either the object exists or timeout. TheHeadObjectInput
type provides the input parameters to describe the object to wait for. Additional waiter functional options can be provided as variadic arguments. These options allow you to modify the SDK's wait attempts and duration.An error is returned when the resource has not reached the desired state within a predetermined expiration period. The expiration period is modeled by the API service team, but can be overridden via the waiter's functional options.
The
WaitUntil
waiter functions are not methods on the client because they are not a part of the API, but higher level concept that add novel functionality. If the waiter functions were methods on the API client, applications mocking the API client would need to mock the waiter as well or experience unexpected behavior.The following is an example of the waiter function's signature.
Mocking the waiter
While there are several ways to mock out the waiter behavior, the most straight forward would be via an unexported package variable. The behavior of the waiter would only need to be replaced if the your mock API clients doesn't include a successful response for the for the operation used by the waiter. Or you want to exercise your code's handling of a waiter failing.
The following demonstrates how a package variable can be used to replace the behavior of the
WaitUntilObjectExists
waiter.The following demonstrates how a test unit would replace the behavior of the waiter.
The text was updated successfully, but these errors were encountered: