Skip to content

Commit e80bbd9

Browse files
authored
Fix flaky complex_layout_scroll_perf__memory & flutter_gallery__memory_nav (#150368)
Initial tap is missing sometimes; either its never delivered or it is delivered before gesture controller is hooked up. 1: Update MemoryTest to have option `requiresTapToStart` guarding the new paths 2: Update the two perf tests that appear to be flaky to output when TAPPED is received 3: Update the MemoryTest to keep tapping while waiting for TAPPED Tested on devicelab: * setting iterations=1 * removing the timeout before READY * running tests in a while loop Before this change, you could get the test to hang often. After this change you'll see "tapping device... [x]" where x is the counter. Fixes flutter/flutter#150096
1 parent 7960958 commit e80bbd9

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

dev/benchmarks/complex_layout/test_memory/scroll_perf.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Future<void> main() async {
2323
final Completer<void> ready = Completer<void>();
2424
runApp(GestureDetector(
2525
onTap: () {
26-
debugPrint('Received tap.');
26+
debugPrint('==== MEMORY BENCHMARK ==== TAPPED ====');
2727
ready.complete();
2828
},
2929
behavior: HitTestBehavior.opaque,
@@ -32,16 +32,14 @@ Future<void> main() async {
3232
),
3333
));
3434
await SchedulerBinding.instance.endOfFrame;
35-
36-
/// Wait 50ms to allow the raster thread to actually put up the frame. (The
37-
/// endOfFrame future ends when we send the data to the engine, before
38-
/// the raster thread has had a chance to rasterize, etc.)
39-
await Future<void>.delayed(const Duration(milliseconds: 50));
4035
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
4136

4237
await ready.future; // waits for tap sent by devicelab task
4338
debugPrint('Continuing...');
4439

40+
// Wait out any errant taps due to synchronization
41+
await Future<void>.delayed(const Duration(milliseconds: 200));
42+
4543
// remove onTap handler, enable pointer events for app
4644
runApp(GestureDetector(
4745
child: const IgnorePointer(

dev/devicelab/bin/tasks/complex_layout_scroll_perf__memory.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ Future<void> main() async {
1313
'${flutterDirectory.path}/dev/benchmarks/complex_layout',
1414
'test_memory/scroll_perf.dart',
1515
'com.yourcompany.complexLayout',
16+
requiresTapToStart: true,
1617
).run);
1718
}

dev/devicelab/bin/tasks/flutter_gallery__memory_nav.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ Future<void> main() async {
1111
'${flutterDirectory.path}/dev/integration_tests/flutter_gallery',
1212
'test_memory/memory_nav.dart',
1313
'io.flutter.demo.gallery',
14+
requiresTapToStart: true,
1415
).run);
1516
}

dev/devicelab/lib/tasks/perf_tests.dart

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,11 +1968,12 @@ class CompileTest {
19681968

19691969
/// Measure application memory usage.
19701970
class MemoryTest {
1971-
MemoryTest(this.project, this.test, this.package);
1971+
MemoryTest(this.project, this.test, this.package, {this.requiresTapToStart = false});
19721972

19731973
final String project;
19741974
final String test;
19751975
final String package;
1976+
final bool requiresTapToStart;
19761977

19771978
/// Completes when the log line specified in the last call to
19781979
/// [prepareForNextMessage] is seen by `adb logcat`.
@@ -2061,6 +2062,38 @@ class MemoryTest {
20612062
await receivedNextMessage;
20622063
}
20632064

2065+
/// Taps the application and looks for acknowldgement.
2066+
///
2067+
/// This is used by several tests to ensure scrolling gestures are installed.
2068+
Future<void> tapNotification() async {
2069+
// Keep "tapping" the device till it responds with the string we expect,
2070+
// or throw an error instead of tying up the infrastructure for 30 minutes.
2071+
prepareForNextMessage('TAPPED');
2072+
bool tapped = false;
2073+
int tapCount = 0;
2074+
await Future.any(<Future<void>>[
2075+
() async {
2076+
while (true) {
2077+
if (tapped) {
2078+
break;
2079+
}
2080+
tapCount += 1;
2081+
print('tapping device... [$tapCount]');
2082+
await device!.tap(100, 100);
2083+
await Future<void>.delayed(const Duration(milliseconds: 100));
2084+
}
2085+
}(),
2086+
() async {
2087+
print('awaiting "tapped" message... (timeout: 10 seconds)');
2088+
try {
2089+
await receivedNextMessage?.timeout(const Duration(seconds: 10));
2090+
} finally {
2091+
tapped = true;
2092+
}
2093+
}(),
2094+
]);
2095+
}
2096+
20642097
/// To change the behavior of the test, override this.
20652098
///
20662099
/// Make sure to call recordStart() and recordEnd() once each in that order.
@@ -2070,10 +2103,11 @@ class MemoryTest {
20702103
Future<void> useMemory() async {
20712104
await launchApp();
20722105
await recordStart();
2106+
if (requiresTapToStart) {
2107+
await tapNotification();
2108+
}
20732109

20742110
prepareForNextMessage('DONE');
2075-
print('tapping device...');
2076-
await device!.tap(100, 100);
20772111
print('awaiting "done" message...');
20782112
await receivedNextMessage;
20792113

dev/integration_tests/flutter_gallery/test_memory/memory_nav.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Future<void> main() async {
2626
final Completer<void> ready = Completer<void>();
2727
runApp(GestureDetector(
2828
onTap: () {
29-
debugPrint('Received tap.');
29+
debugPrint('==== MEMORY BENCHMARK ==== TAPPED ====');
3030
ready.complete();
3131
},
3232
behavior: HitTestBehavior.opaque,
@@ -35,12 +35,14 @@ Future<void> main() async {
3535
),
3636
));
3737
await SchedulerBinding.instance.endOfFrame;
38-
await Future<void>.delayed(const Duration(milliseconds: 50));
3938
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
4039

4140
await ready.future;
4241
debugPrint('Continuing...');
4342

43+
// Wait out any errant taps due to synchronization
44+
await Future<void>.delayed(const Duration(milliseconds: 200));
45+
4446
// remove onTap handler, enable pointer events for app
4547
runApp(GestureDetector(
4648
child: const IgnorePointer(

0 commit comments

Comments
 (0)