Unverified Commit 78f4878f authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Cleanup device lab test and remove a timeout. (#24581)

parent 6c7fb880
......@@ -50,20 +50,22 @@ void main() {
'--verbose',
'-d',
device.deviceId,
'lib/commands.dart'
'lib/commands.dart',
],
);
final StreamController<String> stdout =
StreamController<String>.broadcast();
final StreamController<String> stdout = StreamController<String>.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<void>((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<Map<String, dynamic>> sendRequest(
String method, dynamic params) async {
Future<Map<String, dynamic>> sendRequest(String method, dynamic params) async {
final int requestId = id++;
final Completer<Map<String, dynamic>> response =
Completer<Map<String, dynamic>>();
final StreamSubscription<String> responseSubscription =
stdout.stream.listen((String line) {
final Completer<Map<String, dynamic>> response = Completer<Map<String, dynamic>>();
final StreamSubscription<String> responseSubscription = stdout.stream.listen((String line) {
final Map<String, dynamic> 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<dynamic> hotReload1 = sendRequest('app.restart',
<String, dynamic>{'appId': appId, 'fullRestart': false});
final Future<dynamic> hotReload2 = sendRequest('app.restart',
<String, dynamic>{'appId': appId, 'fullRestart': false});
final Future<List<dynamic>> reloadRequests =
Future.wait<dynamic>(<Future<dynamic>>[hotReload1, hotReload2]);
final dynamic results = await Future
.any<dynamic>(<Future<dynamic>>[run.exitCode, reloadRequests]);
final Future<dynamic> hotReload1 = sendRequest(
'app.restart',
<String, dynamic>{'appId': appId, 'fullRestart': false},
);
final Future<dynamic> hotReload2 = sendRequest(
'app.restart',
<String, dynamic>{'appId': appId, 'fullRestart': false},
);
final Future<List<dynamic>> reloadRequests = Future.wait<dynamic>(<Future<dynamic>>[
hotReload1,
hotReload2,
]);
final dynamic results = await Future.any<dynamic>(<Future<dynamic>>[
run.exitCode,
reloadRequests,
]);
if (!ok)
throw 'App crashed during hot reloads.';
throw 'App failed or crashed during hot reloads.';
final List<dynamic> responses = results;
final List<dynamic> errorResponses =
responses.where((dynamic r) => r['error'] != null).toList();
final List<dynamic> successResponses = responses
.where((dynamic r) =>
r['error'] == null &&
r['result'] != null &&
r['result']['code'] == 0)
.toList();
final List<dynamic> errorResponses = responses.where(
(dynamic r) => r['error'] != null
).toList();
final List<dynamic> 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',
<String, dynamic>{'appId': appId, 'fullRestart': false});
final dynamic hotReload3 = await sendRequest(
'app.restart',
<String, dynamic>{'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);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment