Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions internal/server/smithy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package server

import (
"errors"

"github.com/aws/smithy-go"
)

func hasSmithyCode(err error, code string) bool {
if err == nil {
return false
}
var smithyErr smithy.APIError
if errors.As(err, &smithyErr) && smithyErr.ErrorCode() == code {
return true
}
return false
}
30 changes: 10 additions & 20 deletions internal/server/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go"
)

var errMismatchedETag = fmt.Errorf("mismatched ETags")
Expand All @@ -31,11 +30,8 @@ func (s *storage) EnsureBucketExists() error {
_, err := s.client.CreateBucket(context.Background(), &s3.CreateBucketInput{
Bucket: aws.String(s.bucket),
})
if err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "BucketAlreadyOwnedByYou" {
return nil
}
if hasSmithyCode(err, "BucketAlreadyOwnedByYou") {
return nil
}
return err
}
Expand Down Expand Up @@ -131,23 +127,17 @@ func (s *storage) setDB(items map[string]string, etag string) error {
Key: aws.String(s.name),
Body: bytes.NewReader(bs),
}
if etag == "" {
input.IfNoneMatch = aws.String("*")
} else {
input.IfMatch = aws.String(etag)
}

_, err = s.client.PutObject(ctx, input)
if hasSmithyCode(err, "PreconditionFailed") {
// This is the most critical code in the Valthree server: to enter this
// branch, we must set the If-None-Match or If-Match headers properly,
// which ensures that writes are serialized. Antithesis must exercise
// this code path.
assert.Reachable("Exercised optimistic concurrency control rollback", nil)
return errMismatchedETag
}
if err != nil {
var apiErr smithy.APIError
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "PreconditionFailed" {
// This is the most critical code in the Valthree server: to enter this
// branch, we must set the If-None-Match or If-Match headers properly,
// which ensures that writes are serialized. Antithesis must exercise
// this code path.
assert.Reachable("Exercised optimistic concurrency control rollback", nil)
return errMismatchedETag
}
// Of course, we should also exercise other errors in the write path.
assert.Reachable("Exercised failures writing to object storage", nil)
return fmt.Errorf("put object: %v", err)
Expand Down
Loading