mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fallback to protocol discovery if mdns returns null (#45439)
This commit is contained in:
parent
901eb0fc81
commit
81724bd60f
@ -233,15 +233,16 @@ class AttachCommand extends FlutterCommand {
|
||||
rethrow;
|
||||
}
|
||||
} else if ((device is IOSDevice) || (device is IOSSimulator)) {
|
||||
observatoryUri = Stream<Uri>
|
||||
.fromFuture(
|
||||
MDnsObservatoryDiscovery.instance.getObservatoryUri(
|
||||
appId,
|
||||
device,
|
||||
usesIpv6: usesIpv6,
|
||||
deviceVmservicePort: deviceVmservicePort,
|
||||
)
|
||||
).asBroadcastStream();
|
||||
final Uri uriFromMdns =
|
||||
await MDnsObservatoryDiscovery.instance.getObservatoryUri(
|
||||
appId,
|
||||
device,
|
||||
usesIpv6: usesIpv6,
|
||||
deviceVmservicePort: deviceVmservicePort,
|
||||
);
|
||||
observatoryUri = uriFromMdns == null
|
||||
? null
|
||||
: Stream<Uri>.value(uriFromMdns).asBroadcastStream();
|
||||
}
|
||||
// If MDNS discovery fails or we're not on iOS, fallback to ProtocolDiscovery.
|
||||
if (observatoryUri == null) {
|
||||
|
@ -425,6 +425,58 @@ void main() {
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('fallbacks to protocol observatory if MDNS failed on iOS', () async {
|
||||
const int devicePort = 499;
|
||||
const int hostPort = 42;
|
||||
final MockDeviceLogReader mockLogReader = MockDeviceLogReader();
|
||||
final MockPortForwarder portForwarder = MockPortForwarder();
|
||||
final MockIOSDevice device = MockIOSDevice();
|
||||
final MockHotRunner mockHotRunner = MockHotRunner();
|
||||
final MockHotRunnerFactory mockHotRunnerFactory = MockHotRunnerFactory();
|
||||
when(device.portForwarder).thenReturn(portForwarder);
|
||||
when(device.getLogReader()).thenAnswer((_) => mockLogReader);
|
||||
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
|
||||
.thenAnswer((_) async => hostPort);
|
||||
when(portForwarder.forwardedPorts)
|
||||
.thenReturn(<ForwardedPort>[ForwardedPort(hostPort, devicePort)]);
|
||||
when(portForwarder.unforward(any))
|
||||
.thenAnswer((_) async => null);
|
||||
when(mockHotRunner.attach(appStartedCompleter: anyNamed('appStartedCompleter')))
|
||||
.thenAnswer((_) async => 0);
|
||||
when(mockHotRunnerFactory.build(
|
||||
any,
|
||||
target: anyNamed('target'),
|
||||
debuggingOptions: anyNamed('debuggingOptions'),
|
||||
packagesFilePath: anyNamed('packagesFilePath'),
|
||||
flutterProject: anyNamed('flutterProject'),
|
||||
ipv6: false,
|
||||
)).thenReturn(mockHotRunner);
|
||||
when(mockHotRunner.exited).thenReturn(false);
|
||||
when(mockHotRunner.isWaitingForObservatory).thenReturn(false);
|
||||
|
||||
testDeviceManager.addDevice(device);
|
||||
|
||||
final File foo = fs.file('lib/foo.dart')..createSync();
|
||||
|
||||
// Delete the main.dart file to be sure that attach works without it.
|
||||
fs.file(fs.path.join('lib', 'main.dart')).deleteSync();
|
||||
|
||||
final AttachCommand command = AttachCommand(hotRunnerFactory: mockHotRunnerFactory);
|
||||
await createTestCommandRunner(command).run(<String>['attach', '-t', foo.path, '-v']);
|
||||
|
||||
verify(mockHotRunnerFactory.build(
|
||||
any,
|
||||
target: foo.path,
|
||||
debuggingOptions: anyNamed('debuggingOptions'),
|
||||
packagesFilePath: anyNamed('packagesFilePath'),
|
||||
flutterProject: anyNamed('flutterProject'),
|
||||
ipv6: false,
|
||||
)).called(1);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => testFileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
group('forwarding to given port', () {
|
||||
const int devicePort = 499;
|
||||
const int hostPort = 42;
|
||||
|
Loading…
Reference in New Issue
Block a user