Unverified Commit 159710ec authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] fix response format of flutterVersion, flutterMemoryInfo (#54786)

parent 6a983e73
......@@ -255,7 +255,12 @@ class VMService implements vm_service.VmService {
final Map<String, Object> versionJson = version.toJson();
versionJson['frameworkRevisionShort'] = version.frameworkRevisionShort;
versionJson['engineRevisionShort'] = version.engineRevisionShort;
return versionJson;
return <String, dynamic>{
'result': <String, Object>{
'type': 'Success',
...versionJson,
}
};
});
_delegateService.registerService('flutterVersion', 'Flutter Tools');
......@@ -306,8 +311,21 @@ class VMService implements vm_service.VmService {
}
if (device != null) {
_delegateService.registerServiceCallback('flutterMemoryInfo', (Map<String, dynamic> params) async {
final MemoryInfo result = await device.queryMemoryInfo();
return result.toJson();
try {
final MemoryInfo result = await device.queryMemoryInfo();
return <String, dynamic>{
'result': <String, Object>{
'type': 'Success',
...result.toJson(),
}
};
} on Exception catch (e, st) {
throw vm_service.RPCError(
'Error during memory info query $e\n$st',
RPCErrorCodes.kServerError,
'',
);
}
});
_delegateService.registerService('flutterMemoryInfo', 'Flutter Tools');
}
......@@ -354,6 +372,7 @@ class VMService implements vm_service.VmService {
final io.WebSocket channel = await _openChannel(wsUri.toString(), compression: compression);
final StreamController<dynamic> primary = StreamController<dynamic>();
final StreamController<dynamic> secondary = StreamController<dynamic>();
// Create an instance of the package:vm_service API in addition to the flutter
// tool's to allow gradual migration.
final Completer<void> streamClosedCompleter = Completer<void>();
......@@ -371,7 +390,6 @@ class VMService implements vm_service.VmService {
primary.addError(error, stackTrace);
secondary.addError(error, stackTrace);
});
final vm_service.VmService delegateService = vm_service.VmService(
primary.stream,
channel.add,
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';
import '../src/common.dart';
import 'test_data/basic_project.dart';
import 'test_driver.dart';
import 'test_utils.dart';
void main() {
Directory tempDir;
FlutterRunTestDriver flutter;
test('Flutter Tool VMService methods can be called', () async {
tempDir = createResolvedTempDirectorySync('vmservice_integration_test.');
final BasicProject _project = BasicProject();
await _project.setUpIn(tempDir);
flutter = FlutterRunTestDriver(tempDir);
await flutter.run(withDebugger: true);
final int port = flutter.vmServicePort;
final VmService vmService = await vmServiceConnectUri('ws://localhost:$port/ws');
final Response versionResponse = await vmService.callMethod('s0.flutterVersion');
expect(versionResponse.type, 'Success');
expect(versionResponse.json, containsPair('frameworkRevisionShort', isNotNull));
expect(versionResponse.json, containsPair('engineRevisionShort', isNotNull));
final Response memoryInfoResponse = await vmService.callMethod('s0.flutterMemoryInfo');
expect(memoryInfoResponse.type, 'Success');
});
tearDown(() {
tryToDelete(tempDir);
flutter?.stop();
});
}
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