Set DDS port to requested observatory port for test (#66607)
* Set DDS port to requested observatory port for test * Add test for DDS and observatory ports * Use FakePlatform instead of mock, fix spacing * Use FakeProcessManager instead of mock * Fix analyze issue * Make completer private and add fn for future
This commit is contained in:
@@ -464,7 +464,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
enableObservatory: enableObservatory,
|
||||
startPaused: startPaused,
|
||||
disableServiceAuthCodes: disableServiceAuthCodes,
|
||||
observatoryPort: explicitObservatoryPort,
|
||||
observatoryPort: disableDds ? explicitObservatoryPort : 0,
|
||||
serverPort: server.port,
|
||||
);
|
||||
subprocessActive = true;
|
||||
@@ -495,6 +495,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
// Pipe stdout and stderr from the subprocess to our printStatus console.
|
||||
// We also keep track of what observatory port the engine used, if any.
|
||||
Uri processObservatoryUri;
|
||||
final Uri ddsServiceUri = getDdsServiceUri();
|
||||
_pipeStandardStreamsToConsole(
|
||||
process,
|
||||
reportObservatoryUri: (Uri detectedUri) async {
|
||||
@@ -504,6 +505,7 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
if (!disableDds) {
|
||||
final DartDevelopmentService dds = await DartDevelopmentService.startDartDevelopmentService(
|
||||
detectedUri,
|
||||
serviceUri: ddsServiceUri,
|
||||
enableAuthCodes: !disableServiceAuthCodes,
|
||||
ipv6: host.type == InternetAddressType.IPv6,
|
||||
);
|
||||
@@ -904,6 +906,19 @@ class FlutterPlatform extends PlatformPlugin {
|
||||
return 'Shell subprocess crashed with unexpected exit code $exitCode $when.';
|
||||
}
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
@protected
|
||||
Uri getDdsServiceUri() {
|
||||
return Uri(
|
||||
scheme: 'http',
|
||||
host: (host.type == InternetAddressType.IPv6 ?
|
||||
InternetAddress.loopbackIPv6 :
|
||||
InternetAddress.loopbackIPv4
|
||||
).host,
|
||||
port: explicitObservatoryPort ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// The [_shellProcessClosed] future can't have errors thrown on it because it
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// 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:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
@@ -57,6 +59,49 @@ void main() {
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
group('Observatory and DDS setup', () {
|
||||
Platform fakePlatform;
|
||||
ProcessManager mockProcessManager;
|
||||
FlutterPlatform flutterPlatform;
|
||||
final Map<Type, Generator> contextOverrides = <Type, Generator>{
|
||||
Platform: () => fakePlatform,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
FileSystem: () => fileSystem,
|
||||
};
|
||||
|
||||
setUp(() {
|
||||
fakePlatform = FakePlatform(operatingSystem: 'linux', environment: <String, String>{});
|
||||
mockProcessManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'/',
|
||||
'--observatory-port=0',
|
||||
'--ipv6',
|
||||
'--enable-checked-mode',
|
||||
'--verify-entry-points',
|
||||
'--enable-software-rendering',
|
||||
'--skia-deterministic-rendering',
|
||||
'--enable-dart-profiling',
|
||||
'--non-interactive',
|
||||
'--use-test-fonts',
|
||||
'--packages=.packages',
|
||||
'example.dill'
|
||||
],
|
||||
stdout: 'success',
|
||||
stderr: 'failure',
|
||||
exitCode: 0,
|
||||
)
|
||||
]);
|
||||
flutterPlatform = TestObservatoryFlutterPlatform();
|
||||
});
|
||||
|
||||
testUsingContext('skips setting observatory port and uses the input port for for DDS instead', () async {
|
||||
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
|
||||
final TestObservatoryFlutterPlatform testPlatform = flutterPlatform as TestObservatoryFlutterPlatform;
|
||||
await testPlatform.ddsServiceUriFuture().then((Uri uri) => expect(uri.port, 1234));
|
||||
}, overrides: contextOverrides);
|
||||
});
|
||||
|
||||
group('The FLUTTER_TEST environment variable is passed to the test process', () {
|
||||
MockPlatform mockPlatform;
|
||||
MockProcessManager mockProcessManager;
|
||||
@@ -209,9 +254,48 @@ class TestFlutterPlatform extends FlutterPlatform {
|
||||
enableObservatory: false,
|
||||
buildTestAssets: false,
|
||||
extraFrontEndOptions: <String>[],
|
||||
disableDds: true,
|
||||
);
|
||||
|
||||
@override
|
||||
@protected
|
||||
Future<HttpServer> bind(InternetAddress host, int port) async => MockHttpServer();
|
||||
}
|
||||
|
||||
// A FlutterPlatform that enables observatory.
|
||||
//
|
||||
// Uses a mock HttpServer. We don't want to bind random ports in our CI hosts.
|
||||
class TestObservatoryFlutterPlatform extends FlutterPlatform {
|
||||
TestObservatoryFlutterPlatform() : super(
|
||||
buildMode: BuildMode.debug,
|
||||
shellPath: '/',
|
||||
precompiledDillPath: 'example.dill',
|
||||
host: InternetAddress.loopbackIPv6,
|
||||
port: 0,
|
||||
updateGoldens: false,
|
||||
startPaused: false,
|
||||
enableObservatory: true,
|
||||
explicitObservatoryPort: 1234,
|
||||
buildTestAssets: false,
|
||||
extraFrontEndOptions: <String>[],
|
||||
disableServiceAuthCodes: false,
|
||||
disableDds: false,
|
||||
);
|
||||
|
||||
final Completer<Uri> _ddsServiceUriCompleter = Completer<Uri>();
|
||||
|
||||
Future<Uri> ddsServiceUriFuture() {
|
||||
return _ddsServiceUriCompleter.future;
|
||||
}
|
||||
|
||||
@override
|
||||
@protected
|
||||
Future<HttpServer> bind(InternetAddress host, int port) async => MockHttpServer();
|
||||
|
||||
@override
|
||||
Uri getDdsServiceUri() {
|
||||
final Uri result = super.getDdsServiceUri();
|
||||
_ddsServiceUriCompleter.complete(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user