Unverified Commit 01507bab authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Revert "Switch the way we retrieve the vm_service_port from /hub to iquery, on...

Revert "Switch the way we retrieve the vm_service_port from /hub to iquery, on device. (#114637)" (#114715)

Causes analysis errors:

```
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:513:5 • always_specify_types
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:514:10 • always_specify_types
   info • Avoid method calls or property accesses on a "dynamic" target • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:515:11 • avoid_dynamic_calls
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:515:48 • always_specify_types
   info • Separate the control structure expression from its statement • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:515:77 • always_put_control_body_on_new_line
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:516:7 • always_specify_types
   info • Avoid method calls or property accesses on a "dynamic" target • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:518:11 • avoid_dynamic_calls
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:518:51 • always_specify_types
   info • Separate the control structure expression from its statement • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:518:77 • always_put_control_body_on_new_line
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:519:7 • always_specify_types
   info • Avoid method calls or property accesses on a "dynamic" target • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:521:11 • avoid_dynamic_calls
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:522:21 • always_specify_types
   info • Separate the control structure expression from its statement • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:522:58 • always_put_control_body_on_new_line
  error • The argument type 'dynamic' can't be assigned to the parameter type 'String' • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:524:38 • argument_type_not_assignable
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:540:5 • always_specify_types
   info • Avoid escaping inner quotes by converting surrounding quotes • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:541:14 • avoid_escaping_inner_quotes
   info • Specify type annotations • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:542:5 • always_specify_types
  error • The argument type 'dynamic' can't be assigned to the parameter type 'List<dynamic>' • packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart:544:45 • argument_type_not_assignable
   info • Remove unnecessary backslashes in strings • packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart:114:55 • unnecessary_string_escapes
   info • Remove unnecessary backslashes in strings • packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart:204:55 • unnecessary_string_escapes
   info • Remove unnecessary backslashes in strings • packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart:289:55 • unnecessary_string_escapes
```

This reverts commit b187bc47.
parent b187bc47
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -507,28 +506,6 @@ class FuchsiaRemoteConnection { ...@@ -507,28 +506,6 @@ class FuchsiaRemoteConnection {
_pollDartVms = true; _pollDartVms = true;
} }
/// Helper for getDeviceServicePorts() to extract the vm_service_port from
/// json response.
List<int> getVmServicePortFromInspectSnapshot(List<dynamic> inspectSnapshot) {
final ports = <int>[];
for (final item in inspectSnapshot) {
if (item['payload'] == null || !(item as Map).containsKey('payload')) continue;
final payload = item['payload'];
if (payload['root'] == null || !(payload as Map).containsKey('root')) continue;
final root = payload['root'];
if (root['vm_service_port'] == null ||
!(root as Map).containsKey('vm_service_port')) continue;
final int? port = int.tryParse(root['vm_service_port']);
if (port != null) {
ports.add(port);
}
}
return ports;
}
/// Gets the open Dart VM service ports on a remote Fuchsia device. /// Gets the open Dart VM service ports on a remote Fuchsia device.
/// ///
/// The method attempts to get service ports through an SSH connection. Upon /// The method attempts to get service ports through an SSH connection. Upon
...@@ -537,14 +514,24 @@ class FuchsiaRemoteConnection { ...@@ -537,14 +514,24 @@ class FuchsiaRemoteConnection {
/// found. An exception is thrown in the event of an actual error when /// found. An exception is thrown in the event of an actual error when
/// attempting to acquire the ports. /// attempting to acquire the ports.
Future<List<int>> getDeviceServicePorts() async { Future<List<int>> getDeviceServicePorts() async {
final inspectResult = await _sshCommandRunner final List<String> portPaths = await _sshCommandRunner
.run('iquery --format json show \'**:root:vm_service_port\''); .run('/bin/find /hub -name vmservice-port');
final inspectOutputJson = jsonDecode(inspectResult.join('\n')); final List<int> ports = <int>[];
final List<int> ports = for (final String path in portPaths) {
getVmServicePortFromInspectSnapshot(inspectOutputJson); if (path == '') {
continue;
if (ports.length > 1) { }
throw StateError('More than one Flutter observatory port found'); final List<String> lsOutput =
await _sshCommandRunner.run('/bin/ls $path');
for (final String line in lsOutput) {
if (line == '') {
continue;
}
final int? port = int.tryParse(line);
if (port != null) {
ports.add(port);
}
}
} }
return ports; return ports;
} }
......
...@@ -82,7 +82,7 @@ void main() { ...@@ -82,7 +82,7 @@ void main() {
restoreVmServiceConnectionFunction(); restoreVmServiceConnectionFunction();
}); });
test('end-to-end with one vm connection and flutter view query', () async { test('end-to-end with three vm connections and flutter view query', () async {
int port = 0; int port = 0;
Future<PortForwarder> fakePortForwardingFunction( Future<PortForwarder> fakePortForwardingFunction(
String address, String address,
...@@ -102,76 +102,54 @@ void main() { ...@@ -102,76 +102,54 @@ void main() {
fuchsiaPortForwardingFunction = fakePortForwardingFunction; fuchsiaPortForwardingFunction = fakePortForwardingFunction;
final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner(); final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner();
// Adds some extra junk to make sure the strings will be cleaned up. // Adds some extra junk to make sure the strings will be cleaned up.
fakeRunner.iqueryResponse = <String>[ fakeRunner.findResponse = <String>['/hub/blah/blah/blah/vmservice-port\n'];
'[', fakeRunner.lsResponse = <String>['123\n\n\n', '456 ', '789'];
' {',
' "data_source": "Inspect",',
' "metadata": {',
' "filename": "fuchsia.inspect.Tree",',
' "component_url": "fuchsia-pkg://fuchsia.com/flutter_aot_runner#meta/flutter_runner.cm",',
' "timestamp": 12345678901234',
' },',
' "moniker": "core/session-manager/session\:session/flutter_runner",',
' "payload": {',
' "root": {',
' "vm_service_port": "12345",',
' "16859221": {',
' "empty_tree": "this semantic tree is empty"',
' },',
' "build_info": {',
' "dart_sdk_git_revision": "77e83fcc14fa94049f363d554579f48fbd6bb7a1",',
' "dart_sdk_semantic_version": "2.19.0-317.0.dev",',
' "flutter_engine_git_revision": "563b8e830c697a543bf0a8a9f4ae3edfad86ea86",',
' "fuchsia_sdk_version": "10.20221018.0.1"',
' },',
' "vm": {',
' "dst_status": 1,',
' "get_profile_status": 0,',
' "num_get_profile_calls": 1,',
' "num_intl_provider_errors": 0,',
' "num_on_change_calls": 0,',
' "timezone_content_status": 0,',
' "tz_data_close_status": -1,',
' "tz_data_status": -1',
' }',
' }',
' },',
' "version": 1',
' }',
' ]'
];
fakeRunner.address = 'fe80::8eae:4cff:fef4:9247'; fakeRunner.address = 'fe80::8eae:4cff:fef4:9247';
fakeRunner.interface = 'eno1'; fakeRunner.interface = 'eno1';
final FuchsiaRemoteConnection connection = final FuchsiaRemoteConnection connection =
await FuchsiaRemoteConnection.connectWithSshCommandRunner(fakeRunner); await FuchsiaRemoteConnection.connectWithSshCommandRunner(fakeRunner);
// [fakePortForwardingFunction] will have returned one // [fakePortForwardingFunction] will have returned three different
// forwarded ports, incrementing the port each time by one. (Just a sanity // forwarded ports, incrementing the port each time by one. (Just a sanity
// check that the forwarding port was called). // check that the forwarding port was called).
expect(forwardedPorts.length, 1); expect(forwardedPorts.length, 3);
expect(forwardedPorts[0].remotePort, 12345); expect(forwardedPorts[0].remotePort, 123);
expect(forwardedPorts[1].remotePort, 456);
expect(forwardedPorts[2].remotePort, 789);
expect(forwardedPorts[0].port, 0); expect(forwardedPorts[0].port, 0);
expect(forwardedPorts[1].port, 1);
expect(forwardedPorts[2].port, 2);
// VMs should be accessed via localhost ports given by // VMs should be accessed via localhost ports given by
// [fakePortForwardingFunction]. // [fakePortForwardingFunction].
expect(uriConnections[0], expect(uriConnections[0],
Uri(scheme: 'ws', host: '[::1]', port: 0, path: '/ws')); Uri(scheme:'ws', host:'[::1]', port:0, path:'/ws'));
expect(uriConnections[1],
Uri(scheme:'ws', host:'[::1]', port:1, path:'/ws'));
expect(uriConnections[2],
Uri(scheme:'ws', host:'[::1]', port:2, path:'/ws'));
final List<FlutterView> views = await connection.getFlutterViews(); final List<FlutterView> views = await connection.getFlutterViews();
expect(views, isNot(null)); expect(views, isNot(null));
expect(views.length, 1); expect(views.length, 3);
// Since name can be null, check for the ID on all of them. // Since name can be null, check for the ID on all of them.
expect(views[0].id, 'flutterView0'); expect(views[0].id, 'flutterView0');
expect(views[1].id, 'flutterView1');
expect(views[2].id, 'flutterView2');
expect(views[0].name, equals(null)); expect(views[0].name, equals(null));
expect(views[1].name, 'file://flutterBinary1');
expect(views[2].name, 'file://flutterBinary2');
// Ensure the ports are all closed after stop was called. // Ensure the ports are all closed after stop was called.
await connection.stop(); await connection.stop();
expect(forwardedPorts[0].stopped, true); expect(forwardedPorts[0].stopped, true);
expect(forwardedPorts[1].stopped, true);
expect(forwardedPorts[2].stopped, true);
}); });
test('end-to-end with one vm and remote open port', () async { test('end-to-end with three vms and remote open port', () async {
int port = 0; int port = 0;
Future<PortForwarder> fakePortForwardingFunction( Future<PortForwarder> fakePortForwardingFunction(
String address, String address,
...@@ -192,72 +170,53 @@ void main() { ...@@ -192,72 +170,53 @@ void main() {
fuchsiaPortForwardingFunction = fakePortForwardingFunction; fuchsiaPortForwardingFunction = fakePortForwardingFunction;
final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner(); final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner();
// Adds some extra junk to make sure the strings will be cleaned up. // Adds some extra junk to make sure the strings will be cleaned up.
fakeRunner.iqueryResponse = <String>[ fakeRunner.findResponse = <String>['/hub/blah/blah/blah/vmservice-port\n'];
'[', fakeRunner.lsResponse = <String>['123\n\n\n', '456 ', '789'];
' {',
' "data_source": "Inspect",',
' "metadata": {',
' "filename": "fuchsia.inspect.Tree",',
' "component_url": "fuchsia-pkg://fuchsia.com/flutter_aot_runner#meta/flutter_runner.cm",',
' "timestamp": 12345678901234',
' },',
' "moniker": "core/session-manager/session\:session/flutter_runner",',
' "payload": {',
' "root": {',
' "vm_service_port": "12345",',
' "16859221": {',
' "empty_tree": "this semantic tree is empty"',
' },',
' "build_info": {',
' "dart_sdk_git_revision": "77e83fcc14fa94049f363d554579f48fbd6bb7a1",',
' "dart_sdk_semantic_version": "2.19.0-317.0.dev",',
' "flutter_engine_git_revision": "563b8e830c697a543bf0a8a9f4ae3edfad86ea86",',
' "fuchsia_sdk_version": "10.20221018.0.1"',
' },',
' "vm": {',
' "dst_status": 1,',
' "get_profile_status": 0,',
' "num_get_profile_calls": 1,',
' "num_intl_provider_errors": 0,',
' "num_on_change_calls": 0,',
' "timezone_content_status": 0,',
' "tz_data_close_status": -1,',
' "tz_data_status": -1',
' }',
' }',
' },',
' "version": 1',
' }',
' ]'
];
fakeRunner.address = 'fe80::8eae:4cff:fef4:9247'; fakeRunner.address = 'fe80::8eae:4cff:fef4:9247';
fakeRunner.interface = 'eno1'; fakeRunner.interface = 'eno1';
final FuchsiaRemoteConnection connection = final FuchsiaRemoteConnection connection =
await FuchsiaRemoteConnection.connectWithSshCommandRunner(fakeRunner); await FuchsiaRemoteConnection.connectWithSshCommandRunner(fakeRunner);
expect(forwardedPorts.length, 1); // [fakePortForwardingFunction] will have returned three different
expect(forwardedPorts[0].remotePort, 12345); // forwarded ports, incrementing the port each time by one. (Just a sanity
// check that the forwarding port was called).
expect(forwardedPorts.length, 3);
expect(forwardedPorts[0].remotePort, 123);
expect(forwardedPorts[1].remotePort, 456);
expect(forwardedPorts[2].remotePort, 789);
expect(forwardedPorts[0].port, 0); expect(forwardedPorts[0].port, 0);
expect(forwardedPorts[1].port, 1);
expect(forwardedPorts[2].port, 2);
// VMs should be accessed via the alternate address given by // VMs should be accessed via the alternate address given by
// [fakePortForwardingFunction]. // [fakePortForwardingFunction].
expect(uriConnections[0], expect(uriConnections[0],
Uri(scheme: 'ws', host: '[fe80::1:2%25eno2]', port: 0, path: '/ws')); Uri(scheme:'ws', host:'[fe80::1:2%25eno2]', port:0, path:'/ws'));
expect(uriConnections[1],
Uri(scheme:'ws', host:'[fe80::1:2%25eno2]', port:1, path:'/ws'));
expect(uriConnections[2],
Uri(scheme:'ws', host:'[fe80::1:2%25eno2]', port:2, path:'/ws'));
final List<FlutterView> views = await connection.getFlutterViews(); final List<FlutterView> views = await connection.getFlutterViews();
expect(views, isNot(null)); expect(views, isNot(null));
expect(views.length, 1); expect(views.length, 3);
// Since name can be null, check for the ID on all of them. // Since name can be null, check for the ID on all of them.
expect(views[0].id, 'flutterView0'); expect(views[0].id, 'flutterView0');
expect(views[1].id, 'flutterView1');
expect(views[2].id, 'flutterView2');
expect(views[0].name, equals(null)); expect(views[0].name, equals(null));
expect(views[1].name, 'file://flutterBinary1');
expect(views[2].name, 'file://flutterBinary2');
// Ensure the ports are all closed after stop was called. // Ensure the ports are all closed after stop was called.
await connection.stop(); await connection.stop();
expect(forwardedPorts[0].stopped, true); expect(forwardedPorts[0].stopped, true);
expect(forwardedPorts[1].stopped, true);
expect(forwardedPorts[2].stopped, true);
}); });
test('end-to-end with one vm and ipv4', () async { test('end-to-end with three vms and ipv4', () async {
int port = 0; int port = 0;
Future<PortForwarder> fakePortForwardingFunction( Future<PortForwarder> fakePortForwardingFunction(
String address, String address,
...@@ -277,44 +236,8 @@ void main() { ...@@ -277,44 +236,8 @@ void main() {
fuchsiaPortForwardingFunction = fakePortForwardingFunction; fuchsiaPortForwardingFunction = fakePortForwardingFunction;
final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner(); final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner();
// Adds some extra junk to make sure the strings will be cleaned up. // Adds some extra junk to make sure the strings will be cleaned up.
fakeRunner.iqueryResponse = <String>[ fakeRunner.findResponse = <String>['/hub/blah/blah/blah/vmservice-port\n'];
'[', fakeRunner.lsResponse = <String>['123\n\n\n', '456 ', '789'];
' {',
' "data_source": "Inspect",',
' "metadata": {',
' "filename": "fuchsia.inspect.Tree",',
' "component_url": "fuchsia-pkg://fuchsia.com/flutter_aot_runner#meta/flutter_runner.cm",',
' "timestamp": 12345678901234',
' },',
' "moniker": "core/session-manager/session\:session/flutter_runner",',
' "payload": {',
' "root": {',
' "vm_service_port": "12345",',
' "16859221": {',
' "empty_tree": "this semantic tree is empty"',
' },',
' "build_info": {',
' "dart_sdk_git_revision": "77e83fcc14fa94049f363d554579f48fbd6bb7a1",',
' "dart_sdk_semantic_version": "2.19.0-317.0.dev",',
' "flutter_engine_git_revision": "563b8e830c697a543bf0a8a9f4ae3edfad86ea86",',
' "fuchsia_sdk_version": "10.20221018.0.1"',
' },',
' "vm": {',
' "dst_status": 1,',
' "get_profile_status": 0,',
' "num_get_profile_calls": 1,',
' "num_intl_provider_errors": 0,',
' "num_on_change_calls": 0,',
' "timezone_content_status": 0,',
' "tz_data_close_status": -1,',
' "tz_data_status": -1',
' }',
' }',
' },',
' "version": 1',
' }',
' ]'
];
fakeRunner.address = '196.168.1.4'; fakeRunner.address = '196.168.1.4';
final FuchsiaRemoteConnection connection = final FuchsiaRemoteConnection connection =
...@@ -323,25 +246,39 @@ void main() { ...@@ -323,25 +246,39 @@ void main() {
// [fakePortForwardingFunction] will have returned three different // [fakePortForwardingFunction] will have returned three different
// forwarded ports, incrementing the port each time by one. (Just a sanity // forwarded ports, incrementing the port each time by one. (Just a sanity
// check that the forwarding port was called). // check that the forwarding port was called).
expect(forwardedPorts.length, 1); expect(forwardedPorts.length, 3);
expect(forwardedPorts[0].remotePort, 12345); expect(forwardedPorts[0].remotePort, 123);
expect(forwardedPorts[1].remotePort, 456);
expect(forwardedPorts[2].remotePort, 789);
expect(forwardedPorts[0].port, 0); expect(forwardedPorts[0].port, 0);
expect(forwardedPorts[1].port, 1);
expect(forwardedPorts[2].port, 2);
// VMs should be accessed via the ipv4 loopback. // VMs should be accessed via the ipv4 loopback.
expect(uriConnections[0], expect(uriConnections[0],
Uri(scheme: 'ws', host: '127.0.0.1', port: 0, path: '/ws')); Uri(scheme:'ws', host:'127.0.0.1', port:0, path:'/ws'));
expect(uriConnections[1],
Uri(scheme:'ws', host:'127.0.0.1', port:1, path:'/ws'));
expect(uriConnections[2],
Uri(scheme:'ws', host:'127.0.0.1', port:2, path:'/ws'));
final List<FlutterView> views = await connection.getFlutterViews(); final List<FlutterView> views = await connection.getFlutterViews();
expect(views, isNot(null)); expect(views, isNot(null));
expect(views.length, 1); expect(views.length, 3);
// Since name can be null, check for the ID on all of them. // Since name can be null, check for the ID on all of them.
expect(views[0].id, 'flutterView0'); expect(views[0].id, 'flutterView0');
expect(views[1].id, 'flutterView1');
expect(views[2].id, 'flutterView2');
expect(views[0].name, equals(null)); expect(views[0].name, equals(null));
expect(views[1].name, 'file://flutterBinary1');
expect(views[2].name, 'file://flutterBinary2');
// Ensure the ports are all closed after stop was called. // Ensure the ports are all closed after stop was called.
await connection.stop(); await connection.stop();
expect(forwardedPorts[0].stopped, true); expect(forwardedPorts[0].stopped, true);
expect(forwardedPorts[1].stopped, true);
expect(forwardedPorts[2].stopped, true);
}); });
test('env variable test without remote addr', () async { test('env variable test without remote addr', () async {
...@@ -350,17 +287,22 @@ void main() { ...@@ -350,17 +287,22 @@ void main() {
} }
// Should fail as no env variable has been passed. // Should fail as no env variable has been passed.
expect(failingFunction, throwsA(isA<FuchsiaRemoteConnectionError>())); expect(failingFunction,
throwsA(isA<FuchsiaRemoteConnectionError>()));
}); });
}); });
} }
class FakeSshCommandRunner extends Fake implements SshCommandRunner { class FakeSshCommandRunner extends Fake implements SshCommandRunner {
List<String>? iqueryResponse; List<String>? findResponse;
List<String>? lsResponse;
@override @override
Future<List<String>> run(String command) async { Future<List<String>> run(String command) async {
if (command.startsWith('iquery --format json show')) { if (command.startsWith('/bin/find')) {
return iqueryResponse!; return findResponse!;
}
if (command.startsWith('/bin/ls')) {
return lsResponse!;
} }
throw UnimplementedError(command); throw UnimplementedError(command);
} }
......
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