-
Notifications
You must be signed in to change notification settings - Fork 543
Conformance Tests for Azure Table Storage #1159
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
Conversation
CodeMonkeyLeet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for adding this and fixing up the component!
1d1356c to
f8456bc
Compare
|
@CodeMonkeyLeet thanks for the review. Take another look when you got a chance. |
| err := entity.Insert(storage.FullMetadata, nil) | ||
| if err != nil { | ||
| if isNotFoundError(err) { | ||
| // When entity is not found (set state first time) create it | ||
| entity.OdataEtag = "" | ||
| if etag == "" { | ||
| if req.Options.Concurrency == state.FirstWrite { | ||
| return state.NewETagError(state.ETagMismatch, err) | ||
| } | ||
|
|
||
| return entity.Insert(storage.FullMetadata, nil) | ||
| return entity.Update(true, nil) | ||
| } | ||
| err := entity.Update(false, nil) | ||
| if err != nil { | ||
| if isNotFoundError(err) { | ||
| return state.NewETagError(state.ETagMismatch, err) | ||
| } | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| return err | ||
| return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic LGTM, good job working it out. I would suggest heavily commenting it because the why it works took me a while to unravel that from the structure of the code and the quirks of the conformance test expectations.
I would also suggest explicitly checking for why Insert fails and handling expected cases with Update only.
err := entity.Insert(storage.FullMetadata, nil)
if err != nil {
// If Insert failed because item already exists, try to Update instead per Upsert semantics
if isEntityAlreadyExistsError(err) {
// Always Update using the etag when provided even if Concurrency != FirstWrite.
// This behavior is enforced by test state.go:440 today, where we treat the presence of etag as trumping Concurrency.
// In the future, we should error if an etag is provided when not using FirstWrite (see #2739)
if etag != "" {
uerr := entity.Update(false, nil)
if uerr != nil {
if isNotFoundError(uerr) {
return state.NewETagError(state.ETagMismatch, uerr)
}
return uerr
}
} else if req.Options.Concurrency == state.FirstWrite {
// Otherwise, if FirstWrite was set, but no etag was provided for an Update operation
// explicitly flag it as an error. This is enforced by test state.go:541.
// entity.Update itself does not flag the test case as a mismatch as it does not distinguish
// between nil and "" etags, the initial etag will always be "", which would match on update.
return state.NewETagError(state.ETagMismatch, errors.New("update with Concurrency.FirstWrite without ETag"))
} else {
// Finally, last write semantics without ETag should always perform a force update.
return entity.Update(true, nil)
}
} else {
// Any other unexpected error on Insert is propagated to the caller
return err
}
}
return nilwhere
func isEntityAlreadyExistsError(err error) bool {
azureError, ok := err.(storage.AzureStorageServiceError)
return ok && azureError.Code == "EntityAlreadyExists"
}
CodeMonkeyLeet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Codecov Report
@@ Coverage Diff @@
## master #1159 +/- ##
==========================================
+ Coverage 33.70% 33.77% +0.06%
==========================================
Files 138 138
Lines 11635 11686 +51
==========================================
+ Hits 3922 3947 +25
- Misses 7308 7329 +21
- Partials 405 410 +5
Continue to review full report at Codecov.
|
daixiang0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Conformance Tests for Azure Table Storage
Description
Progress towards #950 : Adds conformance tests for Azure Table Storage Pass.
Fixes incorrect ETag Deletion behavior.