-
Notifications
You must be signed in to change notification settings - Fork 211
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
[CIS-807] Add controllerWillChangeChannels
delegate callback
#1024
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1024 +/- ##
==========================================
+ Coverage 89.95% 89.99% +0.03%
==========================================
Files 213 213
Lines 8962 8986 +24
==========================================
+ Hits 8062 8087 +25
+ Misses 900 899 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
This change makes it possible to deliver callbacks synchronously in the backend queue to backend queue scenario.
7fbe284
to
042acfc
Compare
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!
func controllerWillChangeChannels(_ controller: ChatChannelListController) { | ||
willChangeChannels_called = true | ||
validateQueue() | ||
} |
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.
Just for a consideration, I usually prefer to create a closure that allows to define what will be executed in function so for this case I'd have something like this:
var controllerWillChangeChannelsBody: (ChatChannelListController) -> Void = { _ in }
func controllerWillChangeChannels(_ controller: ChatChannelListController) {
controllerWillChangeChannelsBody(controller)
validateQueue() // not sure if it would come here or to the default body
}
This approach is a bit more verbose but generally gives you flexibility in tests. But as I mentioned, just for future considerations.
Generally it is annoying to switch to this approach, especially with 1100 tests, but it is quite simple and fast to use it in new tests.
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.
@olejnjak I see the benefits of this approach in terms of better flexibility, on the other hand, it also requires bigger setup in the test:
controller.simulateSomething()
AssertAsync.willBeTrue(mock.willChangeChannels_called)
// vs.
var wasCalled = false
mock.controllerWillChangeChannelsBody = { wasCalled = true }
controller.simulateSomething()
AssertAsync.willBeTrue(wasCalled)
It's quite common for our current test setup to have multiple "mocks" for the same object but with different functionalities. So instead of having one almighty global mock, we have multiple local mocks. This basically replicates what you suggest but with concrete types rather than closures.
In this comparison, I don't see any clear winner there. However, thank you for pointing this pattern out. I'm sure there are cases where it works better than the "hardcoded" mock style.
This is mainly to avoid the crashes when
UICollectionView
is updated before it's fully laid out. We already try other (simpler) fixes but none of those worked properly. This is hopefully the last fix of this issue.willChange
callback toListDatabaseObsever
controllerWillChangeChannels
toChatChannelListController
delegateChatChannelListVC
now forces itsUICollectionView
to lay out before the update form the controller comesIf we see this pattern works and helps with the issue, we can extend other list controllers, too.