Cleanup device lab test and remove a timeout. (#24581)
This commit is contained in:
parent
6c7fb88059
commit
78f4878fe1
@ -50,20 +50,22 @@ void main() {
|
|||||||
'--verbose',
|
'--verbose',
|
||||||
'-d',
|
'-d',
|
||||||
device.deviceId,
|
device.deviceId,
|
||||||
'lib/commands.dart'
|
'lib/commands.dart',
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
final StreamController<String> stdout =
|
final StreamController<String> stdout = StreamController<String>.broadcast();
|
||||||
StreamController<String>.broadcast();
|
|
||||||
transformToLines(run.stdout).listen((String line) {
|
transformToLines(run.stdout).listen((String line) {
|
||||||
print('run:stdout: $line');
|
print('run:stdout: $line');
|
||||||
stdout.add(line);
|
stdout.add(line);
|
||||||
final dynamic json = parseFlutterResponse(line);
|
final dynamic json = parseFlutterResponse(line);
|
||||||
if (json != null && json['event'] == 'app.debugPort') {
|
if (json != null) {
|
||||||
vmServicePort = Uri.parse(json['params']['wsUri']).port;
|
if (json['event'] == 'app.debugPort') {
|
||||||
print('service protocol connection available at port $vmServicePort');
|
vmServicePort = Uri.parse(json['params']['wsUri']).port;
|
||||||
} else if (json != null && json['event'] == 'app.started') {
|
print('service protocol connection available at port $vmServicePort');
|
||||||
appId = json['params']['appId'];
|
} else if (json['event'] == 'app.started') {
|
||||||
|
appId = json['params']['appId'];
|
||||||
|
print('application identifier is $appId');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (vmServicePort != null && appId != null && !ready.isCompleted) {
|
if (vmServicePort != null && appId != null && !ready.isCompleted) {
|
||||||
print('run: ready!');
|
print('run: ready!');
|
||||||
@ -73,6 +75,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
transformToLines(run.stderr).listen((String line) {
|
transformToLines(run.stderr).listen((String line) {
|
||||||
stderr.writeln('run:stderr: $line');
|
stderr.writeln('run:stderr: $line');
|
||||||
|
ok = false;
|
||||||
});
|
});
|
||||||
run.exitCode.then<void>((int exitCode) {
|
run.exitCode.then<void>((int exitCode) {
|
||||||
ok = false;
|
ok = false;
|
||||||
@ -81,17 +84,15 @@ void main() {
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
throw 'Failed to run test app.';
|
throw 'Failed to run test app.';
|
||||||
|
|
||||||
final VMServiceClient client =
|
final VMServiceClient client = VMServiceClient.connect(
|
||||||
VMServiceClient.connect('ws://localhost:$vmServicePort/ws');
|
'ws://localhost:$vmServicePort/ws'
|
||||||
|
);
|
||||||
|
|
||||||
int id = 1;
|
int id = 1;
|
||||||
Future<Map<String, dynamic>> sendRequest(
|
Future<Map<String, dynamic>> sendRequest(String method, dynamic params) async {
|
||||||
String method, dynamic params) async {
|
|
||||||
final int requestId = id++;
|
final int requestId = id++;
|
||||||
final Completer<Map<String, dynamic>> response =
|
final Completer<Map<String, dynamic>> response = Completer<Map<String, dynamic>>();
|
||||||
Completer<Map<String, dynamic>>();
|
final StreamSubscription<String> responseSubscription = stdout.stream.listen((String line) {
|
||||||
final StreamSubscription<String> responseSubscription =
|
|
||||||
stdout.stream.listen((String line) {
|
|
||||||
final Map<String, dynamic> json = parseFlutterResponse(line);
|
final Map<String, dynamic> json = parseFlutterResponse(line);
|
||||||
if (json != null && json['id'] == requestId)
|
if (json != null && json['id'] == requestId)
|
||||||
response.complete(json);
|
response.complete(json);
|
||||||
@ -110,27 +111,35 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print('test: sending two hot reloads...');
|
print('test: sending two hot reloads...');
|
||||||
final Future<dynamic> hotReload1 = sendRequest('app.restart',
|
final Future<dynamic> hotReload1 = sendRequest(
|
||||||
<String, dynamic>{'appId': appId, 'fullRestart': false});
|
'app.restart',
|
||||||
final Future<dynamic> hotReload2 = sendRequest('app.restart',
|
<String, dynamic>{'appId': appId, 'fullRestart': false},
|
||||||
<String, dynamic>{'appId': appId, 'fullRestart': false});
|
);
|
||||||
final Future<List<dynamic>> reloadRequests =
|
final Future<dynamic> hotReload2 = sendRequest(
|
||||||
Future.wait<dynamic>(<Future<dynamic>>[hotReload1, hotReload2]);
|
'app.restart',
|
||||||
final dynamic results = await Future
|
<String, dynamic>{'appId': appId, 'fullRestart': false},
|
||||||
.any<dynamic>(<Future<dynamic>>[run.exitCode, reloadRequests]);
|
);
|
||||||
|
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)
|
if (!ok)
|
||||||
throw 'App crashed during hot reloads.';
|
throw 'App failed or crashed during hot reloads.';
|
||||||
|
|
||||||
final List<dynamic> responses = results;
|
final List<dynamic> responses = results;
|
||||||
final List<dynamic> errorResponses =
|
final List<dynamic> errorResponses = responses.where(
|
||||||
responses.where((dynamic r) => r['error'] != null).toList();
|
(dynamic r) => r['error'] != null
|
||||||
final List<dynamic> successResponses = responses
|
).toList();
|
||||||
.where((dynamic r) =>
|
final List<dynamic> successResponses = responses.where(
|
||||||
r['error'] == null &&
|
(dynamic r) => r['error'] == null &&
|
||||||
r['result'] != null &&
|
r['result'] != null &&
|
||||||
r['result']['code'] == 0)
|
r['result']['code'] == 0
|
||||||
.toList();
|
).toList();
|
||||||
|
|
||||||
if (errorResponses.length != 1)
|
if (errorResponses.length != 1)
|
||||||
throw 'Did not receive the expected (exactly one) hot reload error response.';
|
throw 'Did not receive the expected (exactly one) hot reload error response.';
|
||||||
@ -140,8 +149,10 @@ void main() {
|
|||||||
if (successResponses.length != 1)
|
if (successResponses.length != 1)
|
||||||
throw 'Did not receive the expected (exactly one) successful hot reload response.';
|
throw 'Did not receive the expected (exactly one) successful hot reload response.';
|
||||||
|
|
||||||
final dynamic hotReload3 = await sendRequest('app.restart',
|
final dynamic hotReload3 = await sendRequest(
|
||||||
<String, dynamic>{'appId': appId, 'fullRestart': false});
|
'app.restart',
|
||||||
|
<String, dynamic>{'appId': appId, 'fullRestart': false},
|
||||||
|
);
|
||||||
if (hotReload3['error'] != null)
|
if (hotReload3['error'] != null)
|
||||||
throw 'Received an error response from a hot reload after all other hot reloads had completed.';
|
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)
|
if (result != 0)
|
||||||
throw 'Received unexpected exit code $result from run process.';
|
throw 'Received unexpected exit code $result from run process.';
|
||||||
print('test: validating that the app has in fact closed...');
|
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);
|
return TaskResult.success(null);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user