replace package:vm_service_client with package:vm_service in the devicelab project (#41646)
This commit is contained in:
committed by
Jonah Williams
parent
2713ee61f0
commit
4de496a4e5
@@ -56,7 +56,9 @@ class _TaskRunner {
|
||||
});
|
||||
registerExtension('ext.cocoonRunnerReady',
|
||||
(String method, Map<String, String> parameters) async {
|
||||
return ServiceExtensionResponse.result('"ready"');
|
||||
return ServiceExtensionResponse.result(
|
||||
json.encode(<String, dynamic>{'result': 'ready'})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:vm_service_client/vm_service_client.dart';
|
||||
|
||||
import 'package:flutter_devicelab/framework/utils.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:vm_service/vm_service.dart';
|
||||
import 'package:vm_service/vm_service_io.dart';
|
||||
|
||||
/// Runs a task in a separate Dart VM and collects the result using the VM
|
||||
/// service protocol.
|
||||
@@ -44,16 +44,16 @@ Future<Map<String, dynamic>> runTask(
|
||||
runnerFinished = true;
|
||||
});
|
||||
|
||||
final Completer<Uri> uri = Completer<Uri>();
|
||||
final Completer<Uri> uriCompleter = Completer<Uri>();
|
||||
|
||||
final StreamSubscription<String> stdoutSub = runner.stdout
|
||||
.transform<String>(const Utf8Decoder())
|
||||
.transform<String>(const LineSplitter())
|
||||
.listen((String line) {
|
||||
if (!uri.isCompleted) {
|
||||
if (!uriCompleter.isCompleted) {
|
||||
final Uri serviceUri = parseServiceUri(line, prefix: 'Observatory listening on ');
|
||||
if (serviceUri != null)
|
||||
uri.complete(serviceUri);
|
||||
uriCompleter.complete(serviceUri);
|
||||
}
|
||||
if (!silent) {
|
||||
stdout.writeln('[$taskName] [STDOUT] $line');
|
||||
@@ -68,8 +68,12 @@ Future<Map<String, dynamic>> runTask(
|
||||
});
|
||||
|
||||
try {
|
||||
final VMIsolateRef isolate = await _connectToRunnerIsolate(await uri.future);
|
||||
final Map<String, dynamic> taskResult = await isolate.invokeExtension('ext.cocoonRunTask');
|
||||
final VmService client = await _connectToRunner(await uriCompleter.future);
|
||||
final VM vm = await client.getVM();
|
||||
final IsolateRef isolateRef = vm.isolates.single;
|
||||
final Response response = await client.callServiceExtension(
|
||||
'ext.cocoonRunTask', isolateId: isolateRef.id);
|
||||
final Map<String, dynamic> taskResult = response.json;
|
||||
await runner.exitCode;
|
||||
return taskResult;
|
||||
} finally {
|
||||
@@ -81,7 +85,7 @@ Future<Map<String, dynamic>> runTask(
|
||||
}
|
||||
}
|
||||
|
||||
Future<VMIsolateRef> _connectToRunnerIsolate(Uri vmServiceUri) async {
|
||||
Future<VmService> _connectToRunner(Uri vmServiceUri) async {
|
||||
final List<String> pathSegments = <String>[
|
||||
// Add authentication code.
|
||||
if (vmServiceUri.pathSegments.isNotEmpty) vmServiceUri.pathSegments[0],
|
||||
@@ -97,13 +101,14 @@ Future<VMIsolateRef> _connectToRunnerIsolate(Uri vmServiceUri) async {
|
||||
await (await WebSocket.connect(url)).close();
|
||||
|
||||
// Look up the isolate.
|
||||
final VMServiceClient client = VMServiceClient.connect(url);
|
||||
final VmService client = await vmServiceConnectUri(url);
|
||||
final VM vm = await client.getVM();
|
||||
final VMIsolateRef isolate = vm.isolates.single;
|
||||
final String response = await isolate.invokeExtension('ext.cocoonRunnerReady');
|
||||
if (response != 'ready')
|
||||
final IsolateRef isolateRef = vm.isolates.single;
|
||||
final Response response = await client.callServiceExtension(
|
||||
'ext.cocoonRunnerReady', isolateId: isolateRef.id);
|
||||
if (response.json['result'] != 'ready')
|
||||
throw 'not ready yet';
|
||||
return isolate;
|
||||
return client;
|
||||
} catch (error) {
|
||||
if (stopwatch.elapsed > const Duration(seconds: 10))
|
||||
print('VM service still not ready after ${stopwatch.elapsed}: $error\nContinuing to retry...');
|
||||
|
||||
Reference in New Issue
Block a user