Skip to content

Commit 01507ba

Browse files
authored
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 b187bc4.
1 parent b187bc4 commit 01507ba

File tree

2 files changed

+94
-165
lines changed

2 files changed

+94
-165
lines changed

packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'dart:convert';
76
import 'dart:io';
87

98
import 'package:process/process.dart';
@@ -507,28 +506,6 @@ class FuchsiaRemoteConnection {
507506
_pollDartVms = true;
508507
}
509508

510-
/// Helper for getDeviceServicePorts() to extract the vm_service_port from
511-
/// json response.
512-
List<int> getVmServicePortFromInspectSnapshot(List<dynamic> inspectSnapshot) {
513-
final ports = <int>[];
514-
for (final item in inspectSnapshot) {
515-
if (item['payload'] == null || !(item as Map).containsKey('payload')) continue;
516-
final payload = item['payload'];
517-
518-
if (payload['root'] == null || !(payload as Map).containsKey('root')) continue;
519-
final root = payload['root'];
520-
521-
if (root['vm_service_port'] == null ||
522-
!(root as Map).containsKey('vm_service_port')) continue;
523-
524-
final int? port = int.tryParse(root['vm_service_port']);
525-
if (port != null) {
526-
ports.add(port);
527-
}
528-
}
529-
return ports;
530-
}
531-
532509
/// Gets the open Dart VM service ports on a remote Fuchsia device.
533510
///
534511
/// The method attempts to get service ports through an SSH connection. Upon
@@ -537,14 +514,24 @@ class FuchsiaRemoteConnection {
537514
/// found. An exception is thrown in the event of an actual error when
538515
/// attempting to acquire the ports.
539516
Future<List<int>> getDeviceServicePorts() async {
540-
final inspectResult = await _sshCommandRunner
541-
.run('iquery --format json show \'**:root:vm_service_port\'');
542-
final inspectOutputJson = jsonDecode(inspectResult.join('\n'));
543-
final List<int> ports =
544-
getVmServicePortFromInspectSnapshot(inspectOutputJson);
545-
546-
if (ports.length > 1) {
547-
throw StateError('More than one Flutter observatory port found');
517+
final List<String> portPaths = await _sshCommandRunner
518+
.run('/bin/find /hub -name vmservice-port');
519+
final List<int> ports = <int>[];
520+
for (final String path in portPaths) {
521+
if (path == '') {
522+
continue;
523+
}
524+
final List<String> lsOutput =
525+
await _sshCommandRunner.run('/bin/ls $path');
526+
for (final String line in lsOutput) {
527+
if (line == '') {
528+
continue;
529+
}
530+
final int? port = int.tryParse(line);
531+
if (port != null) {
532+
ports.add(port);
533+
}
534+
}
548535
}
549536
return ports;
550537
}

packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart

Lines changed: 76 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void main() {
8282
restoreVmServiceConnectionFunction();
8383
});
8484

85-
test('end-to-end with one vm connection and flutter view query', () async {
85+
test('end-to-end with three vm connections and flutter view query', () async {
8686
int port = 0;
8787
Future<PortForwarder> fakePortForwardingFunction(
8888
String address,
@@ -102,76 +102,54 @@ void main() {
102102
fuchsiaPortForwardingFunction = fakePortForwardingFunction;
103103
final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner();
104104
// Adds some extra junk to make sure the strings will be cleaned up.
105-
fakeRunner.iqueryResponse = <String>[
106-
'[',
107-
' {',
108-
' "data_source": "Inspect",',
109-
' "metadata": {',
110-
' "filename": "fuchsia.inspect.Tree",',
111-
' "component_url": "fuchsia-pkg://fuchsia.com/flutter_aot_runner#meta/flutter_runner.cm",',
112-
' "timestamp": 12345678901234',
113-
' },',
114-
' "moniker": "core/session-manager/session\:session/flutter_runner",',
115-
' "payload": {',
116-
' "root": {',
117-
' "vm_service_port": "12345",',
118-
' "16859221": {',
119-
' "empty_tree": "this semantic tree is empty"',
120-
' },',
121-
' "build_info": {',
122-
' "dart_sdk_git_revision": "77e83fcc14fa94049f363d554579f48fbd6bb7a1",',
123-
' "dart_sdk_semantic_version": "2.19.0-317.0.dev",',
124-
' "flutter_engine_git_revision": "563b8e830c697a543bf0a8a9f4ae3edfad86ea86",',
125-
' "fuchsia_sdk_version": "10.20221018.0.1"',
126-
' },',
127-
' "vm": {',
128-
' "dst_status": 1,',
129-
' "get_profile_status": 0,',
130-
' "num_get_profile_calls": 1,',
131-
' "num_intl_provider_errors": 0,',
132-
' "num_on_change_calls": 0,',
133-
' "timezone_content_status": 0,',
134-
' "tz_data_close_status": -1,',
135-
' "tz_data_status": -1',
136-
' }',
137-
' }',
138-
' },',
139-
' "version": 1',
140-
' }',
141-
' ]'
142-
];
105+
fakeRunner.findResponse = <String>['/hub/blah/blah/blah/vmservice-port\n'];
106+
fakeRunner.lsResponse = <String>['123\n\n\n', '456 ', '789'];
143107
fakeRunner.address = 'fe80::8eae:4cff:fef4:9247';
144108
fakeRunner.interface = 'eno1';
145109

146110
final FuchsiaRemoteConnection connection =
147111
await FuchsiaRemoteConnection.connectWithSshCommandRunner(fakeRunner);
148112

149-
// [fakePortForwardingFunction] will have returned one
113+
// [fakePortForwardingFunction] will have returned three different
150114
// forwarded ports, incrementing the port each time by one. (Just a sanity
151115
// check that the forwarding port was called).
152-
expect(forwardedPorts.length, 1);
153-
expect(forwardedPorts[0].remotePort, 12345);
116+
expect(forwardedPorts.length, 3);
117+
expect(forwardedPorts[0].remotePort, 123);
118+
expect(forwardedPorts[1].remotePort, 456);
119+
expect(forwardedPorts[2].remotePort, 789);
154120
expect(forwardedPorts[0].port, 0);
121+
expect(forwardedPorts[1].port, 1);
122+
expect(forwardedPorts[2].port, 2);
155123

156124
// VMs should be accessed via localhost ports given by
157125
// [fakePortForwardingFunction].
158126
expect(uriConnections[0],
159-
Uri(scheme: 'ws', host: '[::1]', port: 0, path: '/ws'));
127+
Uri(scheme:'ws', host:'[::1]', port:0, path:'/ws'));
128+
expect(uriConnections[1],
129+
Uri(scheme:'ws', host:'[::1]', port:1, path:'/ws'));
130+
expect(uriConnections[2],
131+
Uri(scheme:'ws', host:'[::1]', port:2, path:'/ws'));
160132

161133
final List<FlutterView> views = await connection.getFlutterViews();
162134
expect(views, isNot(null));
163-
expect(views.length, 1);
135+
expect(views.length, 3);
164136
// Since name can be null, check for the ID on all of them.
165137
expect(views[0].id, 'flutterView0');
138+
expect(views[1].id, 'flutterView1');
139+
expect(views[2].id, 'flutterView2');
166140

167141
expect(views[0].name, equals(null));
142+
expect(views[1].name, 'file://flutterBinary1');
143+
expect(views[2].name, 'file://flutterBinary2');
168144

169145
// Ensure the ports are all closed after stop was called.
170146
await connection.stop();
171147
expect(forwardedPorts[0].stopped, true);
148+
expect(forwardedPorts[1].stopped, true);
149+
expect(forwardedPorts[2].stopped, true);
172150
});
173151

174-
test('end-to-end with one vm and remote open port', () async {
152+
test('end-to-end with three vms and remote open port', () async {
175153
int port = 0;
176154
Future<PortForwarder> fakePortForwardingFunction(
177155
String address,
@@ -192,72 +170,53 @@ void main() {
192170
fuchsiaPortForwardingFunction = fakePortForwardingFunction;
193171
final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner();
194172
// Adds some extra junk to make sure the strings will be cleaned up.
195-
fakeRunner.iqueryResponse = <String>[
196-
'[',
197-
' {',
198-
' "data_source": "Inspect",',
199-
' "metadata": {',
200-
' "filename": "fuchsia.inspect.Tree",',
201-
' "component_url": "fuchsia-pkg://fuchsia.com/flutter_aot_runner#meta/flutter_runner.cm",',
202-
' "timestamp": 12345678901234',
203-
' },',
204-
' "moniker": "core/session-manager/session\:session/flutter_runner",',
205-
' "payload": {',
206-
' "root": {',
207-
' "vm_service_port": "12345",',
208-
' "16859221": {',
209-
' "empty_tree": "this semantic tree is empty"',
210-
' },',
211-
' "build_info": {',
212-
' "dart_sdk_git_revision": "77e83fcc14fa94049f363d554579f48fbd6bb7a1",',
213-
' "dart_sdk_semantic_version": "2.19.0-317.0.dev",',
214-
' "flutter_engine_git_revision": "563b8e830c697a543bf0a8a9f4ae3edfad86ea86",',
215-
' "fuchsia_sdk_version": "10.20221018.0.1"',
216-
' },',
217-
' "vm": {',
218-
' "dst_status": 1,',
219-
' "get_profile_status": 0,',
220-
' "num_get_profile_calls": 1,',
221-
' "num_intl_provider_errors": 0,',
222-
' "num_on_change_calls": 0,',
223-
' "timezone_content_status": 0,',
224-
' "tz_data_close_status": -1,',
225-
' "tz_data_status": -1',
226-
' }',
227-
' }',
228-
' },',
229-
' "version": 1',
230-
' }',
231-
' ]'
232-
];
173+
fakeRunner.findResponse = <String>['/hub/blah/blah/blah/vmservice-port\n'];
174+
fakeRunner.lsResponse = <String>['123\n\n\n', '456 ', '789'];
233175
fakeRunner.address = 'fe80::8eae:4cff:fef4:9247';
234176
fakeRunner.interface = 'eno1';
235177
final FuchsiaRemoteConnection connection =
236178
await FuchsiaRemoteConnection.connectWithSshCommandRunner(fakeRunner);
237179

238-
expect(forwardedPorts.length, 1);
239-
expect(forwardedPorts[0].remotePort, 12345);
180+
// [fakePortForwardingFunction] will have returned three different
181+
// forwarded ports, incrementing the port each time by one. (Just a sanity
182+
// check that the forwarding port was called).
183+
expect(forwardedPorts.length, 3);
184+
expect(forwardedPorts[0].remotePort, 123);
185+
expect(forwardedPorts[1].remotePort, 456);
186+
expect(forwardedPorts[2].remotePort, 789);
240187
expect(forwardedPorts[0].port, 0);
188+
expect(forwardedPorts[1].port, 1);
189+
expect(forwardedPorts[2].port, 2);
241190

242191
// VMs should be accessed via the alternate address given by
243192
// [fakePortForwardingFunction].
244193
expect(uriConnections[0],
245-
Uri(scheme: 'ws', host: '[fe80::1:2%25eno2]', port: 0, path: '/ws'));
194+
Uri(scheme:'ws', host:'[fe80::1:2%25eno2]', port:0, path:'/ws'));
195+
expect(uriConnections[1],
196+
Uri(scheme:'ws', host:'[fe80::1:2%25eno2]', port:1, path:'/ws'));
197+
expect(uriConnections[2],
198+
Uri(scheme:'ws', host:'[fe80::1:2%25eno2]', port:2, path:'/ws'));
246199

247200
final List<FlutterView> views = await connection.getFlutterViews();
248201
expect(views, isNot(null));
249-
expect(views.length, 1);
202+
expect(views.length, 3);
250203
// Since name can be null, check for the ID on all of them.
251204
expect(views[0].id, 'flutterView0');
205+
expect(views[1].id, 'flutterView1');
206+
expect(views[2].id, 'flutterView2');
252207

253208
expect(views[0].name, equals(null));
209+
expect(views[1].name, 'file://flutterBinary1');
210+
expect(views[2].name, 'file://flutterBinary2');
254211

255212
// Ensure the ports are all closed after stop was called.
256213
await connection.stop();
257214
expect(forwardedPorts[0].stopped, true);
215+
expect(forwardedPorts[1].stopped, true);
216+
expect(forwardedPorts[2].stopped, true);
258217
});
259218

260-
test('end-to-end with one vm and ipv4', () async {
219+
test('end-to-end with three vms and ipv4', () async {
261220
int port = 0;
262221
Future<PortForwarder> fakePortForwardingFunction(
263222
String address,
@@ -277,44 +236,8 @@ void main() {
277236
fuchsiaPortForwardingFunction = fakePortForwardingFunction;
278237
final FakeSshCommandRunner fakeRunner = FakeSshCommandRunner();
279238
// Adds some extra junk to make sure the strings will be cleaned up.
280-
fakeRunner.iqueryResponse = <String>[
281-
'[',
282-
' {',
283-
' "data_source": "Inspect",',
284-
' "metadata": {',
285-
' "filename": "fuchsia.inspect.Tree",',
286-
' "component_url": "fuchsia-pkg://fuchsia.com/flutter_aot_runner#meta/flutter_runner.cm",',
287-
' "timestamp": 12345678901234',
288-
' },',
289-
' "moniker": "core/session-manager/session\:session/flutter_runner",',
290-
' "payload": {',
291-
' "root": {',
292-
' "vm_service_port": "12345",',
293-
' "16859221": {',
294-
' "empty_tree": "this semantic tree is empty"',
295-
' },',
296-
' "build_info": {',
297-
' "dart_sdk_git_revision": "77e83fcc14fa94049f363d554579f48fbd6bb7a1",',
298-
' "dart_sdk_semantic_version": "2.19.0-317.0.dev",',
299-
' "flutter_engine_git_revision": "563b8e830c697a543bf0a8a9f4ae3edfad86ea86",',
300-
' "fuchsia_sdk_version": "10.20221018.0.1"',
301-
' },',
302-
' "vm": {',
303-
' "dst_status": 1,',
304-
' "get_profile_status": 0,',
305-
' "num_get_profile_calls": 1,',
306-
' "num_intl_provider_errors": 0,',
307-
' "num_on_change_calls": 0,',
308-
' "timezone_content_status": 0,',
309-
' "tz_data_close_status": -1,',
310-
' "tz_data_status": -1',
311-
' }',
312-
' }',
313-
' },',
314-
' "version": 1',
315-
' }',
316-
' ]'
317-
];
239+
fakeRunner.findResponse = <String>['/hub/blah/blah/blah/vmservice-port\n'];
240+
fakeRunner.lsResponse = <String>['123\n\n\n', '456 ', '789'];
318241
fakeRunner.address = '196.168.1.4';
319242

320243
final FuchsiaRemoteConnection connection =
@@ -323,25 +246,39 @@ void main() {
323246
// [fakePortForwardingFunction] will have returned three different
324247
// forwarded ports, incrementing the port each time by one. (Just a sanity
325248
// check that the forwarding port was called).
326-
expect(forwardedPorts.length, 1);
327-
expect(forwardedPorts[0].remotePort, 12345);
249+
expect(forwardedPorts.length, 3);
250+
expect(forwardedPorts[0].remotePort, 123);
251+
expect(forwardedPorts[1].remotePort, 456);
252+
expect(forwardedPorts[2].remotePort, 789);
328253
expect(forwardedPorts[0].port, 0);
254+
expect(forwardedPorts[1].port, 1);
255+
expect(forwardedPorts[2].port, 2);
329256

330257
// VMs should be accessed via the ipv4 loopback.
331258
expect(uriConnections[0],
332-
Uri(scheme: 'ws', host: '127.0.0.1', port: 0, path: '/ws'));
259+
Uri(scheme:'ws', host:'127.0.0.1', port:0, path:'/ws'));
260+
expect(uriConnections[1],
261+
Uri(scheme:'ws', host:'127.0.0.1', port:1, path:'/ws'));
262+
expect(uriConnections[2],
263+
Uri(scheme:'ws', host:'127.0.0.1', port:2, path:'/ws'));
333264

334265
final List<FlutterView> views = await connection.getFlutterViews();
335266
expect(views, isNot(null));
336-
expect(views.length, 1);
267+
expect(views.length, 3);
337268
// Since name can be null, check for the ID on all of them.
338269
expect(views[0].id, 'flutterView0');
270+
expect(views[1].id, 'flutterView1');
271+
expect(views[2].id, 'flutterView2');
339272

340273
expect(views[0].name, equals(null));
274+
expect(views[1].name, 'file://flutterBinary1');
275+
expect(views[2].name, 'file://flutterBinary2');
341276

342277
// Ensure the ports are all closed after stop was called.
343278
await connection.stop();
344279
expect(forwardedPorts[0].stopped, true);
280+
expect(forwardedPorts[1].stopped, true);
281+
expect(forwardedPorts[2].stopped, true);
345282
});
346283

347284
test('env variable test without remote addr', () async {
@@ -350,17 +287,22 @@ void main() {
350287
}
351288

352289
// Should fail as no env variable has been passed.
353-
expect(failingFunction, throwsA(isA<FuchsiaRemoteConnectionError>()));
290+
expect(failingFunction,
291+
throwsA(isA<FuchsiaRemoteConnectionError>()));
354292
});
355293
});
356294
}
357295

358296
class FakeSshCommandRunner extends Fake implements SshCommandRunner {
359-
List<String>? iqueryResponse;
297+
List<String>? findResponse;
298+
List<String>? lsResponse;
360299
@override
361300
Future<List<String>> run(String command) async {
362-
if (command.startsWith('iquery --format json show')) {
363-
return iqueryResponse!;
301+
if (command.startsWith('/bin/find')) {
302+
return findResponse!;
303+
}
304+
if (command.startsWith('/bin/ls')) {
305+
return lsResponse!;
364306
}
365307
throw UnimplementedError(command);
366308
}

0 commit comments

Comments
 (0)