Skip to content

Commit d30ad47

Browse files
authored
Make flutter attach respect the --dds-port flag. (#105560)
1 parent 01822a4 commit d30ad47

File tree

2 files changed

+131
-76
lines changed

2 files changed

+131
-76
lines changed

packages/flutter_tools/lib/src/commands/attach.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ known, it can be explicitly provided to attach via the command-line, e.g.
428428
final DebuggingOptions debuggingOptions = DebuggingOptions.enabled(
429429
buildInfo,
430430
enableDds: enableDds,
431+
ddsPort: ddsPort,
431432
devToolsServerAddress: devToolsServerAddress,
432433
);
433434

packages/flutter_tools/test/integration.shard/flutter_attach_test.dart

Lines changed: 130 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,104 +3,158 @@
33
// found in the LICENSE file.
44

55
import 'package:file/file.dart';
6+
import 'package:flutter_tools/src/base/io.dart';
67
import 'package:vm_service/vm_service.dart';
78

89
import '../src/common.dart';
910
import 'test_data/basic_project.dart';
1011
import 'test_driver.dart';
1112
import 'test_utils.dart';
1213

14+
Future<int> getFreePort() async {
15+
int port = 0;
16+
final ServerSocket serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
17+
port = serverSocket.port;
18+
await serverSocket.close();
19+
return port;
20+
}
21+
1322
void main() {
14-
late FlutterRunTestDriver flutterRun, flutterAttach;
1523
final BasicProject project = BasicProject();
1624
late Directory tempDir;
1725

1826
setUp(() async {
1927
tempDir = createResolvedTempDirectorySync('attach_test.');
2028
await project.setUpIn(tempDir);
21-
flutterRun = FlutterRunTestDriver(tempDir, logPrefix: ' RUN ');
22-
flutterAttach = FlutterRunTestDriver(
23-
tempDir,
24-
logPrefix: 'ATTACH ',
25-
// Only one DDS instance can be connected to the VM service at a time.
26-
// DDS can also only initialize if the VM service doesn't have any existing
27-
// clients, so we'll just let _flutterRun be responsible for spawning DDS.
28-
spawnDdsInstance: false,
29-
);
3029
});
3130

32-
tearDown(() async {
33-
await flutterAttach.detach();
34-
await flutterRun.stop();
31+
tearDown(() {
3532
tryToDelete(tempDir);
3633
});
3734

38-
testWithoutContext('can hot reload', () async {
39-
await flutterRun.run(withDebugger: true);
40-
await flutterAttach.attach(flutterRun.vmServicePort!);
41-
await flutterAttach.hotReload();
42-
});
35+
group('DDS in flutter run', () {
36+
late FlutterRunTestDriver flutterRun, flutterAttach;
37+
setUp(() {
38+
flutterRun = FlutterRunTestDriver(tempDir, logPrefix: ' RUN ');
39+
flutterAttach = FlutterRunTestDriver(
40+
tempDir,
41+
logPrefix: 'ATTACH ',
42+
// Only one DDS instance can be connected to the VM service at a time.
43+
// DDS can also only initialize if the VM service doesn't have any existing
44+
// clients, so we'll just let _flutterRun be responsible for spawning DDS.
45+
spawnDdsInstance: false,
46+
);
47+
});
4348

44-
testWithoutContext('can detach, reattach, hot reload', () async {
45-
await flutterRun.run(withDebugger: true);
46-
await flutterAttach.attach(flutterRun.vmServicePort!);
47-
await flutterAttach.detach();
48-
await flutterAttach.attach(flutterRun.vmServicePort!);
49-
await flutterAttach.hotReload();
50-
});
49+
tearDown(() async {
50+
await flutterAttach.detach();
51+
await flutterRun.stop();
52+
});
53+
54+
testWithoutContext('can hot reload', () async {
55+
await flutterRun.run(withDebugger: true);
56+
await flutterAttach.attach(flutterRun.vmServicePort!);
57+
await flutterAttach.hotReload();
58+
});
59+
60+
testWithoutContext('can detach, reattach, hot reload', () async {
61+
await flutterRun.run(withDebugger: true);
62+
await flutterAttach.attach(flutterRun.vmServicePort!);
63+
await flutterAttach.detach();
64+
await flutterAttach.attach(flutterRun.vmServicePort!);
65+
await flutterAttach.hotReload();
66+
});
67+
68+
testWithoutContext('killing process behaves the same as detach ', () async {
69+
await flutterRun.run(withDebugger: true);
70+
await flutterAttach.attach(flutterRun.vmServicePort!);
71+
await flutterAttach.quit();
72+
flutterAttach = FlutterRunTestDriver(
73+
tempDir,
74+
logPrefix: 'ATTACH-2',
75+
spawnDdsInstance: false,
76+
);
77+
await flutterAttach.attach(flutterRun.vmServicePort!);
78+
await flutterAttach.hotReload();
79+
});
5180

52-
testWithoutContext('killing process behaves the same as detach ', () async {
53-
await flutterRun.run(withDebugger: true);
54-
await flutterAttach.attach(flutterRun.vmServicePort!);
55-
await flutterAttach.quit();
56-
flutterAttach = FlutterRunTestDriver(
57-
tempDir,
58-
logPrefix: 'ATTACH-2',
59-
spawnDdsInstance: false,
60-
);
61-
await flutterAttach.attach(flutterRun.vmServicePort!);
62-
await flutterAttach.hotReload();
81+
testWithoutContext('sets activeDevToolsServerAddress extension', () async {
82+
await flutterRun.run(
83+
startPaused: true,
84+
withDebugger: true,
85+
additionalCommandArgs: <String>['--devtools-server-address', 'http://127.0.0.1:9105'],
86+
);
87+
await flutterRun.resume();
88+
await pollForServiceExtensionValue<String>(
89+
testDriver: flutterRun,
90+
extension: 'ext.flutter.activeDevToolsServerAddress',
91+
continuePollingValue: '',
92+
matches: equals('http://127.0.0.1:9105'),
93+
);
94+
await pollForServiceExtensionValue<String>(
95+
testDriver: flutterRun,
96+
extension: 'ext.flutter.connectedVmServiceUri',
97+
continuePollingValue: '',
98+
matches: isNotEmpty,
99+
);
100+
101+
final Response response = await flutterRun.callServiceExtension('ext.flutter.connectedVmServiceUri');
102+
final String vmServiceUri = response.json!['value'] as String;
103+
104+
// Attach with a different DevTools server address.
105+
await flutterAttach.attach(
106+
flutterRun.vmServicePort!,
107+
additionalCommandArgs: <String>['--devtools-server-address', 'http://127.0.0.1:9110'],
108+
);
109+
await pollForServiceExtensionValue<String>(
110+
testDriver: flutterAttach,
111+
extension: 'ext.flutter.activeDevToolsServerAddress',
112+
continuePollingValue: '',
113+
matches: equals('http://127.0.0.1:9110'),
114+
);
115+
await pollForServiceExtensionValue<String>(
116+
testDriver: flutterRun,
117+
extension: 'ext.flutter.connectedVmServiceUri',
118+
continuePollingValue: '',
119+
matches: equals(vmServiceUri),
120+
);
121+
});
63122
});
64123

65-
testWithoutContext('sets activeDevToolsServerAddress extension', () async {
66-
await flutterRun.run(
67-
startPaused: true,
68-
withDebugger: true,
69-
additionalCommandArgs: <String>['--devtools-server-address', 'http://127.0.0.1:9105'],
70-
);
71-
await flutterRun.resume();
72-
await pollForServiceExtensionValue<String>(
73-
testDriver: flutterRun,
74-
extension: 'ext.flutter.activeDevToolsServerAddress',
75-
continuePollingValue: '',
76-
matches: equals('http://127.0.0.1:9105'),
77-
);
78-
await pollForServiceExtensionValue<String>(
79-
testDriver: flutterRun,
80-
extension: 'ext.flutter.connectedVmServiceUri',
81-
continuePollingValue: '',
82-
matches: isNotEmpty,
83-
);
84-
85-
final Response response = await flutterRun.callServiceExtension('ext.flutter.connectedVmServiceUri');
86-
final String vmServiceUri = response.json!['value'] as String;
87-
88-
// Attach with a different DevTools server address.
89-
await flutterAttach.attach(
90-
flutterRun.vmServicePort!,
91-
additionalCommandArgs: <String>['--devtools-server-address', 'http://127.0.0.1:9110'],
92-
);
93-
await pollForServiceExtensionValue<String>(
94-
testDriver: flutterAttach,
95-
extension: 'ext.flutter.activeDevToolsServerAddress',
96-
continuePollingValue: '',
97-
matches: equals('http://127.0.0.1:9110'),
98-
);
99-
await pollForServiceExtensionValue<String>(
100-
testDriver: flutterRun,
101-
extension: 'ext.flutter.connectedVmServiceUri',
102-
continuePollingValue: '',
103-
matches: equals(vmServiceUri),
104-
);
124+
group('DDS in flutter attach', () {
125+
late FlutterRunTestDriver flutterRun, flutterAttach;
126+
setUp(() {
127+
flutterRun = FlutterRunTestDriver(
128+
tempDir,
129+
logPrefix: ' RUN ',
130+
spawnDdsInstance: false,
131+
);
132+
flutterAttach = FlutterRunTestDriver(
133+
tempDir,
134+
logPrefix: 'ATTACH ',
135+
);
136+
});
137+
138+
tearDown(() async {
139+
await flutterAttach.detach();
140+
await flutterRun.stop();
141+
});
142+
143+
testWithoutContext('uses the designated dds port', () async {
144+
final int ddsPort = await getFreePort();
145+
146+
await flutterRun.run(withDebugger: true);
147+
await flutterAttach.attach(
148+
flutterRun.vmServicePort!,
149+
additionalCommandArgs: <String>[
150+
'--dds-port=$ddsPort',
151+
],
152+
);
153+
154+
final Response response = await flutterAttach.callServiceExtension('ext.flutter.connectedVmServiceUri');
155+
final String vmServiceUriString = response.json!['value'] as String;
156+
final Uri vmServiceUri = Uri.parse(vmServiceUriString);
157+
expect(vmServiceUri.port, equals(ddsPort));
158+
});
105159
});
106160
}

0 commit comments

Comments
 (0)