flutter/packages/flutter_tools/test/integration.shard/devtools_uri_test.dart
Ben Konyi 5ea2be69ca
Reland "Fix issue where DevTools would not be immediately available when using --start-paused (#126698)" (#129368)
**Original Description:**

> Service extensions are unable to handle requests when the isolate they
were registered on is paused. The DevTools launcher logic was waiting
for some service extension invocations to complete before advertising
the already active DevTools instance, but when --start-paused was
provided these requests would never complete, preventing users from
using DevTools to resume the paused isolate.
> 
> Fixes https://github.com/flutter/flutter/issues/126691

**Additional changes in this PR:**

The failures listed in https://github.com/flutter/flutter/pull/128117
appear to be related to a shutdown race. It's possible for the test to
complete while the tool is in the process of starting and advertising
DevTools, so we need to perform a check of `_shutdown` in
`FlutterResidentDevtoolsHandler` before advertising DevTools.

Before the original fix, this check was being performed immediately
after invoking the service extensions, which creates an asynchronous gap
in execution. With #126698, the callsite of the service extensions was
moved and the `_shutdown` check wasn't, allowing for the tool to attempt
to advertise DevTools after the DevTools server had been cleaned up.

---------

Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
2023-06-28 00:16:13 +05:30

54 lines
1.6 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/convert.dart';
import '../src/common.dart';
import 'test_data/basic_project.dart';
import 'test_utils.dart';
void main() {
late Directory tempDir;
final BasicProject project = BasicProject();
setUp(() async {
tempDir = createResolvedTempDirectorySync('run_test.');
await project.setUpIn(tempDir);
});
tearDown(() async {
tryToDelete(tempDir);
});
// Regression test for https://github.com/flutter/flutter/issues/126691
testWithoutContext('flutter run --start-paused prints DevTools URI', () async {
final Completer<void> completer = Completer<void>();
const String matcher = 'The Flutter DevTools debugger and profiler on';
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
final Process process = await processManager.start(<String>[
flutterBin,
'run',
'--start-paused',
'-d',
'flutter-tester',
], workingDirectory: tempDir.path);
final StreamSubscription<String> sub;
sub = process.stdout.transform(utf8.decoder).listen((String message) {
if (message.contains(matcher)) {
completer.complete();
}
});
await completer.future;
await sub.cancel();
process.kill();
await process.exitCode;
});
}