diff --git a/dev/devicelab/bin/tasks/run_machine_concurrent_hot_reload.dart b/dev/devicelab/bin/tasks/run_machine_concurrent_hot_reload.dart index 34d32aeed5d..ee8c86c3aeb 100644 --- a/dev/devicelab/bin/tasks/run_machine_concurrent_hot_reload.dart +++ b/dev/devicelab/bin/tasks/run_machine_concurrent_hot_reload.dart @@ -50,20 +50,22 @@ void main() { '--verbose', '-d', device.deviceId, - 'lib/commands.dart' + 'lib/commands.dart', ], ); - final StreamController stdout = - StreamController.broadcast(); + final StreamController stdout = StreamController.broadcast(); transformToLines(run.stdout).listen((String line) { print('run:stdout: $line'); stdout.add(line); final dynamic json = parseFlutterResponse(line); - if (json != null && json['event'] == 'app.debugPort') { - vmServicePort = Uri.parse(json['params']['wsUri']).port; - print('service protocol connection available at port $vmServicePort'); - } else if (json != null && json['event'] == 'app.started') { - appId = json['params']['appId']; + if (json != null) { + if (json['event'] == 'app.debugPort') { + vmServicePort = Uri.parse(json['params']['wsUri']).port; + print('service protocol connection available at port $vmServicePort'); + } else if (json['event'] == 'app.started') { + appId = json['params']['appId']; + print('application identifier is $appId'); + } } if (vmServicePort != null && appId != null && !ready.isCompleted) { print('run: ready!'); @@ -73,6 +75,7 @@ void main() { }); transformToLines(run.stderr).listen((String line) { stderr.writeln('run:stderr: $line'); + ok = false; }); run.exitCode.then((int exitCode) { ok = false; @@ -81,17 +84,15 @@ void main() { if (!ok) throw 'Failed to run test app.'; - final VMServiceClient client = - VMServiceClient.connect('ws://localhost:$vmServicePort/ws'); + final VMServiceClient client = VMServiceClient.connect( + 'ws://localhost:$vmServicePort/ws' + ); int id = 1; - Future> sendRequest( - String method, dynamic params) async { + Future> sendRequest(String method, dynamic params) async { final int requestId = id++; - final Completer> response = - Completer>(); - final StreamSubscription responseSubscription = - stdout.stream.listen((String line) { + final Completer> response = Completer>(); + final StreamSubscription responseSubscription = stdout.stream.listen((String line) { final Map json = parseFlutterResponse(line); if (json != null && json['id'] == requestId) response.complete(json); @@ -110,27 +111,35 @@ void main() { } print('test: sending two hot reloads...'); - final Future hotReload1 = sendRequest('app.restart', - {'appId': appId, 'fullRestart': false}); - final Future hotReload2 = sendRequest('app.restart', - {'appId': appId, 'fullRestart': false}); - final Future> reloadRequests = - Future.wait(>[hotReload1, hotReload2]); - final dynamic results = await Future - .any(>[run.exitCode, reloadRequests]); + final Future hotReload1 = sendRequest( + 'app.restart', + {'appId': appId, 'fullRestart': false}, + ); + final Future hotReload2 = sendRequest( + 'app.restart', + {'appId': appId, 'fullRestart': false}, + ); + final Future> reloadRequests = Future.wait(>[ + hotReload1, + hotReload2, + ]); + final dynamic results = await Future.any(>[ + run.exitCode, + reloadRequests, + ]); if (!ok) - throw 'App crashed during hot reloads.'; + throw 'App failed or crashed during hot reloads.'; final List responses = results; - final List errorResponses = - responses.where((dynamic r) => r['error'] != null).toList(); - final List successResponses = responses - .where((dynamic r) => - r['error'] == null && - r['result'] != null && - r['result']['code'] == 0) - .toList(); + final List errorResponses = responses.where( + (dynamic r) => r['error'] != null + ).toList(); + final List successResponses = responses.where( + (dynamic r) => r['error'] == null && + r['result'] != null && + r['result']['code'] == 0 + ).toList(); if (errorResponses.length != 1) throw 'Did not receive the expected (exactly one) hot reload error response.'; @@ -140,8 +149,10 @@ void main() { if (successResponses.length != 1) throw 'Did not receive the expected (exactly one) successful hot reload response.'; - final dynamic hotReload3 = await sendRequest('app.restart', - {'appId': appId, 'fullRestart': false}); + final dynamic hotReload3 = await sendRequest( + 'app.restart', + {'appId': appId, 'fullRestart': false}, + ); if (hotReload3['error'] != null) throw 'Received an error response from a hot reload after all other hot reloads had completed.'; @@ -150,7 +161,7 @@ void main() { if (result != 0) throw 'Received unexpected exit code $result from run process.'; print('test: validating that the app has in fact closed...'); - await client.done.timeout(const Duration(seconds: 5)); + await client.done; }); return TaskResult.success(null); });