Unverified Commit 75c853c8 authored by omerlevran46's avatar omerlevran46 Committed by GitHub

[fuchsia] - update getting local host address logic (#75981)

parent 894fdea8
......@@ -68,12 +68,9 @@ class FuchsiaDevFinder {
/// Returns the address of the named device.
///
/// If local is true, then gives the address by which the device reaches the
/// host.
///
/// The string [deviceName] should be the name of the device from the
/// 'list' command, e.g. 'scare-cable-skip-joy'.
Future<String> resolve(String deviceName, {bool local = false}) async {
Future<String> resolve(String deviceName) async {
if (_fuchsiaArtifacts.devFinder == null ||
!_fuchsiaArtifacts.devFinder.existsSync()) {
throwToolExit('Fuchsia device-finder tool not found.');
......@@ -81,7 +78,6 @@ class FuchsiaDevFinder {
final List<String> command = <String>[
_fuchsiaArtifacts.devFinder.path,
'resolve',
if (local) '-local',
'-device-limit', '1',
deviceName,
];
......
......@@ -211,7 +211,6 @@ class FuchsiaDevices extends PollingDeviceDiscovery {
final String name = words[1];
final String resolvedHost = await _fuchsiaSdk.fuchsiaDevFinder.resolve(
name,
local: false,
);
if (resolvedHost == null) {
_logger.printError('Failed to resolve host for Fuchsia device `$name`');
......@@ -297,14 +296,7 @@ class FuchsiaDevice extends Device {
}
// Stop the app if it's currently running.
await stopApp(package);
final String host = await fuchsiaSdk.fuchsiaDevFinder.resolve(
name,
local: true,
);
if (host == null) {
globals.printError('Failed to resolve host for Fuchsia device');
return LaunchResult.failed();
}
final String host = await hostAddress;
// Find out who the device thinks we are.
final int port = await globals.os.findFreePort();
if (port == 0) {
......
......@@ -876,16 +876,17 @@ void main() {
FakeOperatingSystemUtils osUtils;
FakeFuchsiaDeviceTools fuchsiaDeviceTools;
MockFuchsiaSdk fuchsiaSdk;
MockFuchsiaArtifacts fuchsiaArtifacts;
Artifacts artifacts;
FakeProcessManager fakeSuccessfulProcessManager;
FakeProcessManager fakeFailedProcessManager;
File sshConfig;
setUp(() {
memoryFileSystem = MemoryFileSystem.test();
osUtils = FakeOperatingSystemUtils();
fuchsiaDeviceTools = FakeFuchsiaDeviceTools();
fuchsiaSdk = MockFuchsiaSdk();
fuchsiaArtifacts = MockFuchsiaArtifacts();
sshConfig = MemoryFileSystem.test().file('ssh_config')..writeAsStringSync('\n');
artifacts = Artifacts.test();
for (final BuildMode mode in <BuildMode>[BuildMode.debug, BuildMode.release]) {
memoryFileSystem.file(
......@@ -908,6 +909,20 @@ void main() {
platform: TargetPlatform.fuchsia_arm64, mode: mode),
).createSync();
}
fakeSuccessfulProcessManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]);
fakeFailedProcessManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: '',
stderr: '',
exitCode: 1,
),
]);
});
Future<LaunchResult> setupAndStartApp({
......@@ -949,9 +964,9 @@ void main() {
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
......@@ -976,9 +991,9 @@ void main() {
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
......@@ -991,9 +1006,9 @@ void main() {
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
......@@ -1006,9 +1021,23 @@ void main() {
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
'Artifact.genSnapshot.TargetPlatform.fuchsia_arm64.release',
'--deterministic',
'--snapshot_kind=app-aot-elf',
'--elf=build/fuchsia/elf.aotsnapshot',
'build/fuchsia/app_name.dil'
],
),
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]),
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
......@@ -1021,25 +1050,37 @@ void main() {
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
testUsingContext('fail with correct LaunchResult when device-finder fails', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: true, mode: BuildMode.release);
expect(launchResult.started, isFalse);
expect(launchResult.hasObservatory, isFalse);
testUsingContext('fail when cant get ssh config', () async {
expect(() async =>
await setupAndStartApp(prebuilt: true, mode: BuildMode.release),
throwsToolExit(message: 'Cannot interact with device. No ssh config.\n'
'Try setting FUCHSIA_SSH_CONFIG or FUCHSIA_BUILD_DIR.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaSdk: () => MockFuchsiaSdk(devFinder: FailingDevFinder()),
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: null),
OperatingSystemUtils: () => osUtils,
});
testUsingContext('fail when cant get host address', () async {
expect(() async =>
await setupAndStartApp(prebuilt: true, mode: BuildMode.release),
throwsToolExit(message: 'Failed to get local address, aborting.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => fakeFailedProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
OperatingSystemUtils: () => osUtils,
});
......@@ -1051,9 +1092,9 @@ void main() {
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => MockFuchsiaSdk(pm: FailingPM()),
OperatingSystemUtils: () => osUtils,
});
......@@ -1066,9 +1107,9 @@ void main() {
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => FakeFuchsiaDeviceTools(amber: FailingAmberCtl()),
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
......@@ -1081,9 +1122,9 @@ void main() {
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => FakeFuchsiaDeviceTools(tiles: FailingTilesCtl()),
FuchsiaArtifacts: () => fuchsiaArtifacts,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
......@@ -1548,23 +1589,11 @@ class FakeFuchsiaDevFinder implements FuchsiaDevFinder {
}
@override
Future<String> resolve(String deviceName, {bool local = false}) async {
Future<String> resolve(String deviceName) async {
return '192.168.42.10';
}
}
class FailingDevFinder implements FuchsiaDevFinder {
@override
Future<List<String>> list({ Duration timeout }) async {
return null;
}
@override
Future<String> resolve(String deviceName, {bool local = false}) async {
return null;
}
}
class MockFuchsiaSdk extends Mock implements FuchsiaSdk {
MockFuchsiaSdk({
FuchsiaPM pm,
......
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