Fix flakiness in FlutterVSyncWaiterTest.VSyncWorks and FlutterDisplayLinkTest.WorkaroundForFB13482573 (flutter/engine#51405)
- Removes potential source of flakiness where the tests assumes that scheduled block will be performed within certain time period, which, despite the tolerances may not be the case on test runner. - Ensures that `viewDidChangeWindow` notification is not received while invalidating the displayLink and removing the display link view, which could deadlock at the end of `WorkaroundForFB13482573` test because the notification would come while `FlutterDisplayLink` is in `@synchronized` block. *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
@@ -262,8 +262,11 @@ static NSString* const kFlutterDisplayLinkViewDidMoveToWindow =
|
||||
- (void)invalidate {
|
||||
@synchronized(self) {
|
||||
FML_DCHECK([NSThread isMainThread]);
|
||||
[_view removeFromSuperview];
|
||||
// Unregister observer before removing the view to ensure
|
||||
// that the viewDidChangeWindow notification is not received
|
||||
// while in @synchronized block.
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[_view removeFromSuperview];
|
||||
_view = nil;
|
||||
_delegate = nil;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,14 @@ TEST(FlutterVSyncWaiterTest, VSyncWorks) {
|
||||
CFRunLoopStop(CFRunLoopGetCurrent());
|
||||
}];
|
||||
|
||||
__block CFTimeInterval expectedStartUntil;
|
||||
// Warm up tick is scheduled immediately in a scheduled block. Schedule another
|
||||
// block here to determine the maximum time when the warm up tick should be
|
||||
// scheduled.
|
||||
[waiter waitForVSync:kWarmUpBaton];
|
||||
[[NSRunLoop currentRunLoop] performBlock:^{
|
||||
expectedStartUntil = CACurrentMediaTime();
|
||||
}];
|
||||
|
||||
// Reference vsync to setup phase.
|
||||
CFTimeInterval now = CACurrentMediaTime();
|
||||
@@ -166,15 +173,22 @@ TEST(FlutterVSyncWaiterTest, VSyncWorks) {
|
||||
// Vsync without baton should pause the display link.
|
||||
[displayLink tickWithTimestamp:now + 3.5 * displayLink.nominalOutputRefreshPeriod
|
||||
targetTimestamp:now + 5 * displayLink.nominalOutputRefreshPeriod];
|
||||
// Make sure to run the timer scheduled in display link callback.
|
||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.02, NO);
|
||||
|
||||
CFTimeInterval start = CACurrentMediaTime();
|
||||
while (!displayLink.paused) {
|
||||
// Make sure to run the timer scheduled in display link callback.
|
||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.02, NO);
|
||||
if (CACurrentMediaTime() - start > 1.0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(displayLink.paused);
|
||||
|
||||
EXPECT_EQ(entries.size(), size_t(4));
|
||||
|
||||
// Warm up frame should be presented as soon as possible.
|
||||
EXPECT_TRUE(fabs(entries[0].timestamp - now) < 0.005);
|
||||
EXPECT_TRUE(fabs(entries[0].targetTimestamp - now) < 0.005);
|
||||
EXPECT_TRUE(entries[0].timestamp <= expectedStartUntil);
|
||||
EXPECT_TRUE(entries[0].targetTimestamp <= expectedStartUntil);
|
||||
EXPECT_EQ(entries[0].baton, kWarmUpBaton);
|
||||
|
||||
EXPECT_DOUBLE_EQ(entries[1].timestamp, now + displayLink.nominalOutputRefreshPeriod);
|
||||
|
||||
Reference in New Issue
Block a user