-
Notifications
You must be signed in to change notification settings - Fork 130
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
Fix delta sync bug #263
Fix delta sync bug #263
Conversation
Delta sync was using wrong hash to store the data in the local cache. This caused delta sync to fail intermittently.
Co-Authored-By: Rohan Dubal <[email protected]>
Co-Authored-By: Rohan Dubal <[email protected]>
} | ||
|
||
func testWithAllValuesFilled() { | ||
let subscriptionWithSync = AppSyncSubscriptionWithSync<OnUpvotePostSubscription, ListPostsQuery, ListPostsQuery>(appSyncClient: appsyncClient!, |
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.
nit: Here and throughout: please start arguments on the next line after the opening parens to fix indent, or reformat the generic parameters to line these up. As it stands, the actual method call and arguments are off the screen :)
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.
Fixed the indentation, removed the generics
|
||
class AppSyncSubscriptionWithSyncTests: XCTestCase { | ||
|
||
var appsyncClient: AWSAppSyncClient? |
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.
You could make this an implicitly unwrapped optional (var appsyncClient: AWSAppSyncClient!
) to avoid constantly force unwrapping in the body of your tests.
Reasoning:
- You can't do anything meaningful without the client, so a crash immediately fails the tests instead of getting into an unexpected state (as for example if you had an optional chain or a
guard
that simply exited early without asserting anything) - You have a proper try/catch block in
setUp
to catch the setup failures immediately
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.
Fixed
} | ||
} | ||
|
||
|
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.
Nit, remove extra lines
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.
Removed
@@ -133,6 +133,7 @@ | |||
70C68E4D132FE62623DB8C07 /* Pods_AWSAppSyncTestHostApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C707001F57B091A8A001CAB /* Pods_AWSAppSyncTestHostApp.framework */; }; | |||
8032C5415EF414C038394D69 /* Pods_AWSAppSyncTestCommon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 74071C397A83DEA980BB2F4C /* Pods_AWSAppSyncTestCommon.framework */; }; | |||
A70604C0C722923A70C937A1 /* Pods_AWSAppSyncTestApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57F5A94352E1ABE35159489D /* Pods_AWSAppSyncTestApp.framework */; }; | |||
B48056BC22A992E200E4F742 /* AppSyncSubscriptionWithSyncTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B48056BB22A992E200E4F742 /* AppSyncSubscriptionWithSyncTests.swift */; }; |
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.
nit: sort the folder by name
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.
Sorted
### Bug Fixes | ||
|
||
* Fix a bug where delta sync was not correctly storing/ retrieving the `lastSyncTime`. See [issue #232](https://github.com/awslabs/aws-mobile-appsync-sdk-ios/issues/232) | ||
* **Breaking API Change** To fix the delta sync logic, there was a change in the hashing function used internally. This change can cause the existing app to ignore the cache for the first sync and fetch data using base query. Subsequent sync operation should work as normal. |
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.
What happens to any existing cache data? Will it be re-used, overwritten, ignored and left to grow stale?
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.
Existing cache data will be ignored.
|
||
let variables = baseQuery.variables?.sorted(by: { $0.0 < $1.0 }).description ?? "" | ||
baseString += type(of: baseQuery).requestString + variables | ||
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.
nit, remove trailing whitespace
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.
Removed
if let subscription = subscription { | ||
let variables = subscription.variables?.description ?? "" | ||
baseString = type(of: subscription).requestString + variables | ||
let variables = subscription.variables?.sorted(by: { $0.0 < $1.0 }).description ?? "" |
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.
nit: spacing
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.
Fixed spacing
} | ||
|
||
|
||
private class GraphGetQuery: GraphQLQuery { |
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.
No need for this to be namespaced to the test, just extract to a private class in the same file
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.
Moved outside
XCTAssertEqual(result1, result2, "Hash value should be equal for the two sync operation") | ||
|
||
} | ||
|
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.
Please add a test that ensures that cases that specify the same operation for both baseQuery
and deltaQuery
work as expected.
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.
Added
Delta sync was using wrong hash to store the data in the local cache. This caused
delta sync to fail intermittently.
Issue #:
#232
Description of changes:
Hash calculation used in delta calculation was wrong and was producing different results on the same input. This was caused due to the unordered representation of swift Dictionary object which we used for creating hash. This PR addresses this issue by sorting the dictionary content and then using it for hash calculation.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.