-
Notifications
You must be signed in to change notification settings - Fork 199
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: DataStore E2E Integration Tests #596
Conversation
@@ -45,8 +45,10 @@ class DataStoreEndToEndTests: SyncEngineIntegrationTestBase { | |||
return | |||
} | |||
|
|||
if post.id != newPost.id { return } |
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.
let post = try? mutationEvent.decodeModel() as? Post
above at line 42 will fail the test if there is an existing mutation in the queue and is not a post. if we are enforcing that the hub listener only reacts to data for this test then it should include decoding the right model as well, ie.
guard if let post = try? mutationEvent.decodeModel() as? Post, post.id != newPost.id else {
return
}
```
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.
Something like this?
guard let mutationEvent = payload.data as? MutationEvent else {
XCTFail("Can't cast payload as mutation event")
return
}
guard let post = try? mutationEvent.decodeModel() as? Post, post.id != newPost.id else { return }
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.
I agree with the intent of this proposal, but a couple of things:
-
You need to fix the
id
equality check:guard let post = try? mutationEvent.decodeModel() as? Post, post.id == newPost.id else { return }
Otherwise you'll always be guaranteed to check the wrong post.
-
Please add a comment explaining that this check is to protect against stray events being processed after the test has completed, and that it shouldn't be construed as a pattern necessary for production applications.
Description of changes:
Added a filter inside
testCreateMutateDelete()
,testCreateThenMutateWithCondition()
andtestCreateThenMutateWithConditionFailOnSync()
to make sure these three tests only care about related payload receiving from hub listener.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.