Fix issues running integration tests through DAP debug adapter (#104618)

* Fix issues running integration tests through DAP

These adapters were incorrectly trying to connect a DDS instance even when Flutter would create its own. This change disables DDS in the DAP layer and leaves it to Flutter (although it passes `--no-dds` on to Flutter if provided to the DAP process).

Also fixes an issue where we would unnecessarily connect the VM Service for tests even in 'noDebug' mode because of a change/fix that now includes a 'vmServiceUri' in the `test.startedProcess` event.
This commit is contained in:
Danny Tuppeny
2022-05-26 09:36:30 +01:00
committed by GitHub
parent 2aa348b940
commit 147020366a
5 changed files with 170 additions and 45 deletions

View File

@@ -25,15 +25,24 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
required this.fileSystem,
required this.platform,
super.ipv6,
super.enableDds,
bool enableDds = true,
super.enableAuthCodes,
super.logger,
});
}) : _enableDds = enableDds,
// Always disable in the DAP layer as it's handled in the spawned
// 'flutter' process.
super(enableDds: false);
FileSystem fileSystem;
Platform platform;
Process? _process;
/// Whether DDS should be enabled in the Flutter process.
///
/// We never enable DDS in the DAP process for Flutter, so this value is not
/// the same as what is passed to the base class, which is always provided 'false'.
final bool _enableDds;
@override
final FlutterLaunchRequestArguments Function(Map<String, Object?> obj)
parseLaunchArgs = FlutterLaunchRequestArguments.fromJson;
@@ -136,6 +145,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
final List<String> toolArgs = <String>[
'attach',
'--machine',
if (!_enableDds) '--no-dds',
if (vmServiceUri != null)
...<String>['--debug-uri', vmServiceUri],
];
@@ -249,6 +259,7 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
final List<String> toolArgs = <String>[
'run',
'--machine',
if (!_enableDds) '--no-dds',
if (enableDebugger) '--start-paused',
// Structured errors are enabled by default, but since we don't connect
// the VM Service for noDebug, we need to disable them so that error text

View File

@@ -25,15 +25,24 @@ class FlutterTestDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArgum
required this.fileSystem,
required this.platform,
super.ipv6,
super.enableDds,
bool enableDds = true,
super.enableAuthCodes,
super.logger,
});
}) : _enableDds = enableDds,
// Always disable in the DAP layer as it's handled in the spawned
// 'flutter' process.
super(enableDds: false);
FileSystem fileSystem;
Platform platform;
Process? _process;
/// Whether DDS should be enabled in the Flutter process.
///
/// We never enable DDS in the DAP process for Flutter, so this value is not
/// the same as what is passed to the base class, which is always provided 'false'.
final bool _enableDds;
@override
final FlutterLaunchRequestArguments Function(Map<String, Object?> obj)
parseLaunchArgs = FlutterLaunchRequestArguments.fromJson;
@@ -78,6 +87,22 @@ class FlutterTestDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArgum
terminatePids(ProcessSignal.sigkill);
}
/// Whether or not the user requested debugging be enabled.
///
/// For debugging to be enabled, the user must have chosen "Debug" (and not
/// "Run") in the editor (which maps to the DAP `noDebug` field).
bool get enableDebugger {
final DartCommonLaunchAttachRequestArguments args = this.args;
if (args is FlutterLaunchRequestArguments) {
// Invert DAP's noDebug flag, treating it as false (so _do_ debug) if not
// provided.
return !(args.noDebug ?? false);
}
// Otherwise (attach), always debug.
return true;
}
/// Called by [launchRequest] to request that we actually start the tests to be run/debugged.
///
/// For debugging, this should start paused, connect to the VM Service, set
@@ -86,12 +111,13 @@ class FlutterTestDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArgum
Future<void> launchImpl() async {
final FlutterLaunchRequestArguments args = this.args as FlutterLaunchRequestArguments;
final bool debug = !(args.noDebug ?? false);
final bool debug = enableDebugger;
final String? program = args.program;
final List<String> toolArgs = <String>[
'test',
'--machine',
if (!_enableDds) '--no-dds',
if (debug) '--start-paused',
];
@@ -207,8 +233,9 @@ class FlutterTestDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArgum
/// Handles the test.processStarted event from Flutter that provides the VM Service URL.
void _handleTestStartedProcess(Map<String, Object?> params) {
final String? vmServiceUriString = params['observatoryUri'] as String?;
// For no-debug mode, this event is still sent, but has a null URI.
if (vmServiceUriString == null) {
// For no-debug mode, this event may be still sent so ignore it if we know
// we're not debugging, or its URI is null.
if (!enableDebugger || vmServiceUriString == null) {
return;
}
final Uri vmServiceUri = Uri.parse(vmServiceUriString);