Skip to content

Commit

Permalink
[flutter_tools] fix response format of flutterVersion, flutterMemoryI…
Browse files Browse the repository at this point in the history
…nfo (#54786)
  • Loading branch information
jonahwilliams committed Apr 14, 2020
1 parent 6a983e7 commit 159710e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
26 changes: 22 additions & 4 deletions packages/flutter_tools/lib/src/vmservice.dart
Expand Up @@ -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');

Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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>();
Expand All @@ -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,
Expand Down
@@ -0,0 +1,43 @@
// 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();
});
}

0 comments on commit 159710e

Please sign in to comment.