Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Reland: Started waiting for the notifications locally before asserting side-effects #25257

Merged
merged 3 commits into from
Mar 29, 2021

Conversation

gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Mar 26, 2021

Relanding #25226

It had to be reverted because other tests were leaking FlutterViewControllers because of OCMock stubbing. I couldn't get ocmock to release the objects so I had to make my own mock engine.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Comment on lines +19 to +33
/// Sometimes we have to use a custom mock to avoid retain cycles in ocmock.
@interface FlutterEnginePartialMock : FlutterEngine
@property(nonatomic, strong) FlutterBasicMessageChannel* lifecycleChannel;
@property(nonatomic, weak) FlutterViewController* viewController;
@property(nonatomic, assign) BOOL didCallNotifyLowMemory;
@end

@implementation FlutterEnginePartialMock
@synthesize viewController;
@synthesize lifecycleChannel;

- (void)notifyLowMemory {
_didCallNotifyLowMemory = YES;
}
@end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmagman This is what I had to do in order to get rid of the cycles. I would hope that upgrading ocmock would also fix this, but it was hard to upgrade ocmock because it changed its dependencies, it's complicated to get GN working with it.

@@ -970,5 +970,6 @@ - (void)testAccessibilityMessageAfterDeletion {
});
latch.Wait();
OCMVerify([messenger cleanupConnection:connection]);
[engine stopMocking];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be superfluous now. I don't think it hurts anything. Once I got everything working I didn't try to cull any of the previous work I did.

[viewController beginAppearanceTransition:NO animated:NO];
[viewController endAppearanceTransition];
OCMVerify([self.mockEngine notifyLowMemory]);
XCTAssertTrue(mockEngine.didCallNotifyLowMemory);
Copy link
Member

@jmagman jmagman Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can actually allocate a FlutterEngine subclass without mocking, is the subclass necessary? Does it work if you want for an XCTKVOExpectation?

[self keyValueObservingExpectation:mockEngine keyPath:@"notifyLowMemory" handler:nil]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean could we use a real FlutterEngine? There shouldn't be a keyPath notifyLowMemory on a standard FlutterEngine, that would only get created if there was a property called notifyLowMemory or if we manually registered one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the subclass is also necessary for setting the lifecycle channel, not just needed for the notifyLowMemory stuff)

@gaaclarke gaaclarke requested a review from jmagman March 29, 2021 20:20
Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gaaclarke gaaclarke added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 29, 2021
@gaaclarke gaaclarke merged commit 27bf114 into flutter:master Mar 29, 2021
@gaaclarke gaaclarke removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Mar 29, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 30, 2021
chandarrengoog pushed a commit to chandarrengoog/engine that referenced this pull request Mar 30, 2021
duanqz pushed a commit to duanqz/engine that referenced this pull request Apr 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants