[fuchsia] Get Dart VM service ports from The Hub (#25332)

This commit is contained in:
Zachary Anderson
2018-12-17 11:10:47 -08:00
committed by GitHub
parent 9619b53d06
commit b18a2b1794
5 changed files with 61 additions and 72 deletions

View File

@@ -523,24 +523,21 @@ class FuchsiaRemoteConnection {
/// found. An exception is thrown in the event of an actual error when
/// attempting to acquire the ports.
Future<List<int>> getDeviceServicePorts() async {
// TODO(awdavies): This is using a temporary workaround rather than a
// well-defined service, and will be deprecated in the near future.
final List<String> lsOutput =
await _sshCommandRunner.run('ls /tmp/dart.services');
final List<String> portPaths =
await _sshCommandRunner.run('find /hub -name vmservice-port');
final List<int> ports = <int>[];
// The output of lsOutput is a list of available ports as the Fuchsia dart
// service advertises. An example lsOutput would look like:
//
// [ '31782\n', '1234\n', '11967' ]
for (String s in lsOutput) {
final String trimmed = s.trim();
final int lastSpace = trimmed.lastIndexOf(' ');
final String lastWord = trimmed.substring(lastSpace + 1);
if ((lastWord != '.') && (lastWord != '..')) {
final int value = int.tryParse(lastWord);
if (value != null) {
ports.add(value);
for (String path in portPaths) {
if (path == '') {
continue;
}
final List<String> lsOutput = await _sshCommandRunner.run('ls $path');
for (String line in lsOutput) {
if (line == '') {
continue;
}
final int port = int.tryParse(line);
if (port != null) {
ports.add(port);
}
}
}

View File

@@ -21,7 +21,9 @@ void main() {
setUp(() {
mockRunner = MockSshCommandRunner();
// Adds some extra junk to make sure the strings will be cleaned up.
when(mockRunner.run(any)).thenAnswer((_) =>
when(mockRunner.run(argThat(startsWith('find')))).thenAnswer((_) =>
Future<List<String>>.value(<String>['/hub/blah/blah/blah/vmservice-port\n']));
when(mockRunner.run(argThat(startsWith('ls')))).thenAnswer((_) =>
Future<List<String>>.value(<String>['123\n\n\n', '456 ', '789']));
const String address = 'fe80::8eae:4cff:fef4:9247';
const String interface = 'eno1';