Add support for Dart Development Service (DDS) in Flutter Tools (#59114)
This commit is contained in:
@@ -7,6 +7,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/dds.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
@@ -71,6 +72,7 @@ void main() {
|
||||
|
||||
FakeDeviceLogReader mockLogReader;
|
||||
MockPortForwarder portForwarder;
|
||||
MockDartDevelopmentService mockDds;
|
||||
MockAndroidDevice device;
|
||||
MockHttpClient httpClient;
|
||||
|
||||
@@ -78,6 +80,7 @@ void main() {
|
||||
mockLogReader = FakeDeviceLogReader();
|
||||
portForwarder = MockPortForwarder();
|
||||
device = MockAndroidDevice();
|
||||
mockDds = MockDartDevelopmentService();
|
||||
when(device.portForwarder)
|
||||
.thenReturn(portForwarder);
|
||||
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
|
||||
@@ -86,6 +89,8 @@ void main() {
|
||||
.thenReturn(<ForwardedPort>[ForwardedPort(hostPort, devicePort)]);
|
||||
when(portForwarder.unforward(any))
|
||||
.thenAnswer((_) async => null);
|
||||
when(device.dds).thenReturn(mockDds);
|
||||
when(mockDds.startDartDevelopmentService(any, false)).thenReturn(null);
|
||||
|
||||
final HttpClientRequest httpClientRequest = MockHttpClientRequest();
|
||||
httpClient = MockHttpClient();
|
||||
@@ -286,11 +291,14 @@ void main() {
|
||||
const int hostPort = 42;
|
||||
final FakeDeviceLogReader mockLogReader = FakeDeviceLogReader();
|
||||
final MockPortForwarder portForwarder = MockPortForwarder();
|
||||
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
|
||||
final MockAndroidDevice device = MockAndroidDevice();
|
||||
final MockHotRunner mockHotRunner = MockHotRunner();
|
||||
final MockHotRunnerFactory mockHotRunnerFactory = MockHotRunnerFactory();
|
||||
when(device.portForwarder)
|
||||
.thenReturn(portForwarder);
|
||||
when(device.dds)
|
||||
.thenReturn(mockDds);
|
||||
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
|
||||
.thenAnswer((_) async => hostPort);
|
||||
when(portForwarder.forwardedPorts)
|
||||
@@ -309,6 +317,7 @@ void main() {
|
||||
)).thenReturn(mockHotRunner);
|
||||
when(mockHotRunner.exited).thenReturn(false);
|
||||
when(mockHotRunner.isWaitingForObservatory).thenReturn(false);
|
||||
when(mockDds.startDartDevelopmentService(any, false)).thenReturn(null);
|
||||
|
||||
testDeviceManager.addDevice(device);
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
@@ -359,10 +368,14 @@ void main() {
|
||||
const int hostPort = 42;
|
||||
final FakeDeviceLogReader mockLogReader = FakeDeviceLogReader();
|
||||
final MockPortForwarder portForwarder = MockPortForwarder();
|
||||
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
|
||||
final MockIOSDevice device = MockIOSDevice();
|
||||
final MockHotRunner mockHotRunner = MockHotRunner();
|
||||
final MockHotRunnerFactory mockHotRunnerFactory = MockHotRunnerFactory();
|
||||
when(device.portForwarder).thenReturn(portForwarder);
|
||||
when(device.portForwarder)
|
||||
.thenReturn(portForwarder);
|
||||
when(device.dds)
|
||||
.thenReturn(mockDds);
|
||||
when(device.getLogReader(includePastLogs: anyNamed('includePastLogs')))
|
||||
.thenAnswer((_) => mockLogReader);
|
||||
when(portForwarder.forward(devicePort, hostPort: anyNamed('hostPort')))
|
||||
@@ -383,6 +396,7 @@ void main() {
|
||||
)).thenReturn(mockHotRunner);
|
||||
when(mockHotRunner.exited).thenReturn(false);
|
||||
when(mockHotRunner.isWaitingForObservatory).thenReturn(false);
|
||||
when(mockDds.startDartDevelopmentService(any, false)).thenReturn(null);
|
||||
|
||||
testDeviceManager.addDevice(device);
|
||||
|
||||
@@ -415,6 +429,7 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
portForwarder = MockPortForwarder();
|
||||
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
|
||||
device = MockAndroidDevice();
|
||||
|
||||
when(device.portForwarder)
|
||||
@@ -425,6 +440,10 @@ void main() {
|
||||
.thenReturn(<ForwardedPort>[ForwardedPort(hostPort, devicePort)]);
|
||||
when(portForwarder.unforward(any))
|
||||
.thenAnswer((_) async => null);
|
||||
when(device.dds)
|
||||
.thenReturn(mockDds);
|
||||
when(mockDds.startDartDevelopmentService(any, any))
|
||||
.thenReturn(null);
|
||||
});
|
||||
|
||||
testUsingContext('succeeds in ipv4 mode', () async {
|
||||
@@ -795,6 +814,7 @@ class TestHotRunnerFactory extends HotRunnerFactory {
|
||||
}
|
||||
}
|
||||
|
||||
class MockDartDevelopmentService extends Mock implements DartDevelopmentService {}
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class MockProcess extends Mock implements Process {}
|
||||
class MockHttpClientRequest extends Mock implements HttpClientRequest {}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:file/memory.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/android/android_device.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/dds.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
@@ -67,6 +68,12 @@ void main() {
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
void applyDdsMocks(Device device) {
|
||||
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
|
||||
when(device.dds).thenReturn(mockDds);
|
||||
when(mockDds.startDartDevelopmentService(any, any)).thenReturn(null);
|
||||
}
|
||||
|
||||
testUsingContext('returns 1 when test file is not found', () async {
|
||||
testDeviceManager.addDevice(MockDevice());
|
||||
|
||||
@@ -188,7 +195,9 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('returns 0 when test ends successfully', () async {
|
||||
testDeviceManager.addDevice(MockAndroidDevice());
|
||||
final MockAndroidDevice mockDevice = MockAndroidDevice();
|
||||
applyDdsMocks(mockDevice);
|
||||
testDeviceManager.addDevice(mockDevice);
|
||||
|
||||
final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart');
|
||||
final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
|
||||
@@ -227,7 +236,9 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('returns exitCode set by test runner', () async {
|
||||
testDeviceManager.addDevice(MockDevice());
|
||||
final MockDevice mockDevice = MockDevice();
|
||||
applyDdsMocks(mockDevice);
|
||||
testDeviceManager.addDevice(mockDevice);
|
||||
|
||||
final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart');
|
||||
final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
|
||||
@@ -374,6 +385,7 @@ void main() {
|
||||
|
||||
Future<Device> appStarterSetup() async {
|
||||
final Device mockDevice = MockDevice();
|
||||
applyDdsMocks(mockDevice);
|
||||
testDeviceManager.addDevice(mockDevice);
|
||||
|
||||
final FakeDeviceLogReader mockDeviceLogReader = FakeDeviceLogReader();
|
||||
@@ -509,6 +521,7 @@ void main() {
|
||||
|
||||
Future<Device> appStarterSetup() async {
|
||||
final Device mockDevice = MockDevice();
|
||||
applyDdsMocks(mockDevice);
|
||||
testDeviceManager.addDevice(mockDevice);
|
||||
|
||||
final FakeDeviceLogReader mockDeviceLogReader = FakeDeviceLogReader();
|
||||
@@ -792,5 +805,5 @@ class MockDevice extends Mock implements Device {
|
||||
}
|
||||
|
||||
class MockAndroidDevice extends Mock implements AndroidDevice { }
|
||||
|
||||
class MockDartDevelopmentService extends Mock implements DartDevelopmentService { }
|
||||
class MockLaunchResult extends Mock implements LaunchResult { }
|
||||
|
||||
@@ -139,6 +139,8 @@ class TestFlutterDevice extends FlutterDevice {
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
|
||||
bool disableDds = false,
|
||||
bool ipv6 = false,
|
||||
}) async {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
@@ -728,6 +728,7 @@ void main() {
|
||||
fuchsiaDevice,
|
||||
expectedIsolateName,
|
||||
(Uri uri) async => fakeVmServiceHost.vmService,
|
||||
(Device device, Uri uri) => null,
|
||||
true, // only poll once.
|
||||
);
|
||||
|
||||
|
||||
@@ -578,6 +578,8 @@ class TestFlutterDevice extends FlutterDevice {
|
||||
ReloadMethod reloadMethod,
|
||||
GetSkSLMethod getSkSLMethod,
|
||||
PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
|
||||
bool disableDds = false,
|
||||
bool ipv6 = false,
|
||||
}) async {
|
||||
throw exception;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ void main() {
|
||||
|
||||
expect(await fallbackDiscovery.discover(
|
||||
assumedDevicePort: 23,
|
||||
deivce: null,
|
||||
device: null,
|
||||
hostVmservicePort: 1,
|
||||
packageId: null,
|
||||
usesIpv6: false,
|
||||
@@ -86,7 +86,7 @@ void main() {
|
||||
});
|
||||
expect(await fallbackDiscovery.discover(
|
||||
assumedDevicePort: 23,
|
||||
deivce: null,
|
||||
device: null,
|
||||
hostVmservicePort: 1,
|
||||
packageId: null,
|
||||
usesIpv6: false,
|
||||
@@ -117,7 +117,7 @@ void main() {
|
||||
|
||||
expect(await fallbackDiscovery.discover(
|
||||
assumedDevicePort: 23,
|
||||
deivce: null,
|
||||
device: null,
|
||||
hostVmservicePort: 1,
|
||||
packageId: 'hello',
|
||||
usesIpv6: false,
|
||||
@@ -139,7 +139,7 @@ void main() {
|
||||
|
||||
expect(await fallbackDiscovery.discover(
|
||||
assumedDevicePort: 23,
|
||||
deivce: null,
|
||||
device: null,
|
||||
hostVmservicePort: 1,
|
||||
packageId: 'hello',
|
||||
usesIpv6: false,
|
||||
@@ -161,7 +161,7 @@ void main() {
|
||||
|
||||
expect(await fallbackDiscovery.discover(
|
||||
assumedDevicePort: 23,
|
||||
deivce: null,
|
||||
device: null,
|
||||
hostVmservicePort: 1,
|
||||
packageId: 'hello',
|
||||
usesIpv6: false,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/base/dds.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
import 'package:file/memory.dart';
|
||||
@@ -1645,8 +1646,11 @@ void main() {
|
||||
testUsingContext('connect sets up log reader', () => testbed.run(() async {
|
||||
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
|
||||
final MockDevice mockDevice = MockDevice();
|
||||
final MockDartDevelopmentService mockDds = MockDartDevelopmentService();
|
||||
final MockDeviceLogReader mockLogReader = MockDeviceLogReader();
|
||||
when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(mockLogReader);
|
||||
when(mockDevice.dds).thenReturn(mockDds);
|
||||
when(mockDds.startDartDevelopmentService(any, any)).thenReturn(null);
|
||||
|
||||
final TestFlutterDevice flutterDevice = TestFlutterDevice(
|
||||
mockDevice,
|
||||
@@ -1678,6 +1682,7 @@ void main() {
|
||||
}
|
||||
|
||||
class MockFlutterDevice extends Mock implements FlutterDevice {}
|
||||
class MockDartDevelopmentService extends Mock implements DartDevelopmentService {}
|
||||
class MockVMService extends Mock implements vm_service.VmService {}
|
||||
class MockDevFS extends Mock implements DevFS {}
|
||||
class MockDevice extends Mock implements Device {}
|
||||
|
||||
@@ -21,7 +21,14 @@ void main() {
|
||||
tempDir = createResolvedTempDirectorySync('attach_test.');
|
||||
await _project.setUpIn(tempDir);
|
||||
_flutterRun = FlutterRunTestDriver(tempDir, logPrefix: ' RUN ');
|
||||
_flutterAttach = FlutterRunTestDriver(tempDir, logPrefix: 'ATTACH ');
|
||||
_flutterAttach = FlutterRunTestDriver(
|
||||
tempDir,
|
||||
logPrefix: 'ATTACH ',
|
||||
// Only one DDS instance can be connected to the VM service at a time.
|
||||
// DDS can also only initialize if the VM service doesn't have any existing
|
||||
// clients, so we'll just let _flutterRun be responsible for spawning DDS.
|
||||
spawnDdsInstance: false,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
@@ -58,7 +65,11 @@ void main() {
|
||||
await _flutterRun.run(withDebugger: true);
|
||||
await _flutterAttach.attach(_flutterRun.vmServicePort);
|
||||
await _flutterAttach.quit();
|
||||
_flutterAttach = FlutterRunTestDriver(tempDir, logPrefix: 'ATTACH-2');
|
||||
_flutterAttach = FlutterRunTestDriver(
|
||||
tempDir,
|
||||
logPrefix: 'ATTACH-2',
|
||||
spawnDdsInstance: false,
|
||||
);
|
||||
await _flutterAttach.attach(_flutterRun.vmServicePort);
|
||||
await _flutterAttach.hotReload();
|
||||
});
|
||||
|
||||
@@ -25,7 +25,6 @@ void main() {
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await _flutter.stop();
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
@@ -51,7 +50,6 @@ void main() {
|
||||
// Complete anyway in case we don't see the 'Another exception' line.
|
||||
completer.complete();
|
||||
});
|
||||
|
||||
await _flutter.stop();
|
||||
|
||||
expect(stdout.toString(), contains(_exceptionStart));
|
||||
@@ -62,7 +60,6 @@ void main() {
|
||||
|
||||
await _flutter.run(startPaused: true, withDebugger: true, structuredErrors: true, chrome: true);
|
||||
await _flutter.resume();
|
||||
|
||||
final Completer<void> completer = Completer<void>();
|
||||
bool lineFound = false;
|
||||
|
||||
|
||||
@@ -428,6 +428,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
FlutterRunTestDriver(
|
||||
Directory projectFolder, {
|
||||
String logPrefix,
|
||||
this.spawnDdsInstance = true,
|
||||
}) : super(projectFolder, logPrefix: logPrefix);
|
||||
|
||||
String _currentRunningAppId;
|
||||
@@ -447,6 +448,8 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
'run',
|
||||
if (!chrome)
|
||||
'--disable-service-auth-codes',
|
||||
if (!spawnDdsInstance)
|
||||
'--disable-dds',
|
||||
'--machine',
|
||||
'-d',
|
||||
if (chrome)
|
||||
@@ -479,6 +482,8 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
<String>[
|
||||
'attach',
|
||||
'--machine',
|
||||
if (!spawnDdsInstance)
|
||||
'--disable-dds',
|
||||
'-d',
|
||||
'flutter-tester',
|
||||
'--debug-port',
|
||||
@@ -680,6 +685,8 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
void _throwErrorResponse(String message) {
|
||||
throw '$message\n\n$_lastResponse\n\n${_errorBuffer.toString()}'.trim();
|
||||
}
|
||||
|
||||
final bool spawnDdsInstance;
|
||||
}
|
||||
|
||||
class FlutterTestTestDriver extends FlutterTestDriver {
|
||||
|
||||
@@ -39,6 +39,15 @@ void main() {
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
test('getSupportedProtocols includes DDS', () async {
|
||||
final ProtocolList protocolList =
|
||||
await vmService.getSupportedProtocols();
|
||||
expect(protocolList.protocols, hasLength(2));
|
||||
for (final Protocol protocol in protocolList.protocols) {
|
||||
expect(protocol.protocolName, anyOf('VM Service', 'DDS'));
|
||||
}
|
||||
});
|
||||
|
||||
test('flutterVersion can be called', () async {
|
||||
final Response response =
|
||||
await vmService.callServiceExtension('s0.flutterVersion');
|
||||
|
||||
Reference in New Issue
Block a user