@@ -2167,6 +2167,11 @@ class CompileTest {
21672167class MemoryTest {
21682168 MemoryTest(this.project, this.test, this.package, {this.requiresTapToStart = false});
21692169
2170+ static const Duration nextMessageTimeout = Duration(seconds: 60);
2171+ static const Duration _tapRetryTimeout = Duration(seconds: 1);
2172+ static const int _maxTapIterations = 10;
2173+ static const int _tapCoordinate = 100;
2174+
21702175 final String project;
21712176 final String test;
21722177 final String package;
@@ -2185,6 +2190,18 @@ class MemoryTest {
21852190 _receivedNextMessage = Completer<void>();
21862191 }
21872192
2193+ /// Completes [receivedNextMessage] if [line] contains the expected
2194+ /// memory benchmark marker for the last [prepareForNextMessage] call.
2195+ @visibleForTesting
2196+ void handleLogcatLine(String line) {
2197+ if (_nextMessage != null &&
2198+ line.contains('==== MEMORY BENCHMARK ==== $_nextMessage ====') &&
2199+ !(_receivedNextMessage?.isCompleted ?? true)) {
2200+ _nextMessage = null;
2201+ _receivedNextMessage?.complete();
2202+ }
2203+ }
2204+
21882205 int get iterationCount => 10;
21892206
21902207 Device? get device => _device;
@@ -2199,11 +2216,7 @@ class MemoryTest {
21992216 await device!.unlock();
22002217 await flutter('packages', options: <String>['get']);
22012218
2202- final StreamSubscription<String> adb = device!.logcat.listen((String data) {
2203- if (data.contains('==== MEMORY BENCHMARK ==== $_nextMessage ====')) {
2204- _receivedNextMessage?.complete();
2205- }
2206- });
2219+ final StreamSubscription<String> adb = device!.logcat.listen(handleLogcatLine);
22072220
22082221 for (var iteration = 0; iteration < iterationCount; iteration += 1) {
22092222 print('running memory test iteration $iteration...');
@@ -2250,8 +2263,8 @@ class MemoryTest {
22502263 'run',
22512264 options: <String>['--verbose', '--release', '--no-resident', '-d', device!.deviceId, test],
22522265 );
2253- print('awaiting "ready" message...');
2254- await receivedNextMessage;
2266+ print('awaiting "ready" message... (timeout: $nextMessageTimeout) ');
2267+ await receivedNextMessage?.timeout(nextMessageTimeout) ;
22552268 }
22562269
22572270 /// Taps the application and looks for acknowledgement.
@@ -2261,29 +2274,19 @@ class MemoryTest {
22612274 // Keep "tapping" the device till it responds with the string we expect,
22622275 // or throw an error instead of tying up the infrastructure for 30 minutes.
22632276 prepareForNextMessage('TAPPED');
2264- var tapped = false;
2265- var tapCount = 0;
2266- await Future.any(<Future<void>>[
2267- () async {
2268- while (true) {
2269- if (tapped) {
2270- break;
2271- }
2272- tapCount += 1;
2273- print('tapping device... [$tapCount]');
2274- await device!.tap(100, 100);
2275- await Future<void>.delayed(const Duration(milliseconds: 100));
2276- }
2277- }(),
2278- () async {
2279- print('awaiting "tapped" message... (timeout: 10 seconds)');
2280- try {
2281- await receivedNextMessage?.timeout(const Duration(seconds: 10));
2282- } finally {
2283- tapped = true;
2277+ for (var tapCount = 1; tapCount <= _maxTapIterations; tapCount += 1) {
2278+ print('tapping device... [$tapCount]');
2279+ await device!.tap(_tapCoordinate, _tapCoordinate);
2280+ print('awaiting "tapped" message... (timeout: $_tapRetryTimeout)');
2281+ try {
2282+ await receivedNextMessage?.timeout(_tapRetryTimeout);
2283+ return;
2284+ } on TimeoutException {
2285+ if (tapCount == _maxTapIterations) {
2286+ rethrow;
22842287 }
2285- }(),
2286- ]);
2288+ }
2289+ }
22872290 }
22882291
22892292 /// To change the behavior of the test, override this.
@@ -2300,8 +2303,8 @@ class MemoryTest {
23002303 }
23012304
23022305 prepareForNextMessage('DONE');
2303- print('awaiting "done" message...');
2304- await receivedNextMessage;
2306+ print('awaiting "done" message... (timeout: $nextMessageTimeout) ');
2307+ await receivedNextMessage?.timeout(nextMessageTimeout) ;
23052308
23062309 await recordEnd();
23072310 }
@@ -2398,6 +2401,8 @@ String _reportedDurationTestToString(ReportedDurationTestFlavor flavor) {
23982401class ReportedDurationTest {
23992402 ReportedDurationTest(this.flavor, this.project, this.test, this.package, this.durationPattern);
24002403
2404+ static const Duration durationTimeout = Duration(seconds: 60);
2405+
24012406 final ReportedDurationTestFlavor flavor;
24022407 final String project;
24032408 final String test;
@@ -2421,7 +2426,7 @@ class ReportedDurationTest {
24212426 await flutter('packages', options: <String>['get']);
24222427
24232428 final StreamSubscription<String> adb = device!.logcat.listen((String data) {
2424- if (durationPattern.hasMatch(data)) {
2429+ if (durationPattern.hasMatch(data) && !durationCompleter.isCompleted ) {
24252430 durationCompleter.complete(int.parse(durationPattern.firstMatch(data)!.group(1)!));
24262431 }
24272432 });
@@ -2439,7 +2444,7 @@ class ReportedDurationTest {
24392444 ],
24402445 );
24412446
2442- final int duration = await durationCompleter.future;
2447+ final int duration = await durationCompleter.future.timeout(durationTimeout) ;
24432448 print('terminating...');
24442449 await device!.stop(package);
24452450 await adb.cancel();
0 commit comments