Skip to content

Commit ed7a2c2

Browse files
authored
Deflake hybrid_android_views_integration_test (flutter#191830)
This change resolves two sources of flakiness in `hybrid_android_views_integration_test`: 1. **FutureDataHandler Lazy Await:** Updates `FutureDataHandler` to lazily create and await a `Completer` when a driver message arrives before `registerHandler` is called by `onPlatformViewCreated`, preventing premature "unsupported driver message" errors. 2. **Disable Page Route Animations:** Switches `_pushPage` to use `PageRouteBuilder` with zero transition duration and adds `waitUntilNoTransientCallbacks()` before running motion event replay tests, eliminating in-flight coordinate transformation offsets on embedded platform views. should help with flutter#190992
1 parent 98c435f commit ed7a2c2

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎dev/integration_tests/hybrid_android_views/lib/future_data_handler.dart‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ class FutureDataHandler {
1818

1919
/// Registers a lazy handler that will be invoked on the next message from the driver.
2020
Completer<DriverHandler> registerHandler(String key) {
21-
_handlers[key] = Completer<DriverHandler>();
22-
return _handlers[key]!;
21+
final Completer<DriverHandler>? existing = _handlers[key];
22+
if (existing != null && !existing.isCompleted) {
23+
return existing;
24+
}
25+
final completer = Completer<DriverHandler>();
26+
_handlers[key] = completer;
27+
return completer;
2328
}
2429

2530
Future<String> handleMessage(String? message) async {
26-
if (_handlers[message] == null) {
27-
return 'Unsupported driver message: $message.\n'
28-
'Supported messages are: ${_handlers.keys}.';
31+
if (message == null) {
32+
return 'Unsupported driver message: null';
2933
}
30-
final DriverHandler handler = await _handlers[message]!.future;
34+
final Completer<DriverHandler> completer = _handlers.putIfAbsent(
35+
message,
36+
() => Completer<DriverHandler>(),
37+
);
38+
final DriverHandler handler = await completer.future;
3139
return handler();
3240
}
3341
}

‎dev/integration_tests/hybrid_android_views/lib/main.dart‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ class Home extends StatelessWidget {
4343
}
4444

4545
void _pushPage(BuildContext context, PageWidget page) {
46-
Navigator.of(context).push(MaterialPageRoute<void>(builder: (_) => Scaffold(body: page)));
46+
Navigator.of(context).push(
47+
PageRouteBuilder<void>(
48+
pageBuilder: (
49+
BuildContext context,
50+
Animation<double> animation,
51+
Animation<double> secondaryAnimation,
52+
) {
53+
return Scaffold(body: page);
54+
},
55+
transitionDuration: Duration.zero,
56+
reverseTransitionDuration: Duration.zero,
57+
),
58+
);
4759
}
4860
}

‎dev/integration_tests/hybrid_android_views/test_driver/main_test.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Future<void> main() async {
2121
final SerializableFinder motionEventsListTile = find.byValueKey('MotionEventsListTile');
2222
await driver.tap(motionEventsListTile);
2323
await driver.waitFor(find.byValueKey('PlatformView'));
24+
await driver.waitUntilNoTransientCallbacks();
2425
try {
2526
final String errorMessage = await driver.requestData('run test');
2627
expect(errorMessage, '');

0 commit comments

Comments
 (0)