48e13f6078
function TEST=test cases added to pkg/dartdev/test/commands/compilation_server_test.dart and pkg/dartdev/test/commands/run_test.dart This CL factors out shutDownOrForgetResidentFrontendCompiler from the CompilationIssue.serverError handling code in RunCommand. This CL also changes the error handling logic of `dart run --resident` and `dart compilation-server shutdown` to stop them from displaying unactionable errors to the user, and instead have them handle those errors more gracefully. Issue: https://github.com/dart-lang/sdk/issues/54245 Change-Id: I214392911dbb44e3273ffd36f8f59f791b33494c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362520 Reviewed-by: Ben Konyi <bkonyi@google.com>
178 lines
6.1 KiB
Dart
178 lines
6.1 KiB
Dart
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
|
// for details. 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:io';
|
|
|
|
import 'package:dartdev/src/resident_frontend_constants.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:test/test.dart';
|
|
|
|
import '../utils.dart';
|
|
|
|
void main() {
|
|
group('compilation-server', () {
|
|
late TestProject p;
|
|
final compilationServerStartRegExp = RegExp(
|
|
r'The Resident Frontend Compiler is listening at ([a-zA-Z0-9:/=_\-\.\[\]]+)\n'
|
|
'\nRun dart compilation-server shutdown to terminate the process.',
|
|
);
|
|
final compilationServerShutdownRegExp = RegExp(
|
|
r'The Resident Frontend Compiler instance at ([a-zA-Z0-9:/=_\-\.\[\]]+) was successfully shutdown.',
|
|
);
|
|
|
|
test('shutdown issued with no server running', () async {
|
|
p = project();
|
|
final serverInfoFile = path.join(p.dirPath, 'info');
|
|
final result = await p.run([
|
|
'compilation-server',
|
|
'shutdown',
|
|
'--$residentCompilerInfoFileOption=$serverInfoFile',
|
|
]);
|
|
|
|
expect(
|
|
result.stdout,
|
|
contains('No resident frontend compiler instance running'),
|
|
);
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), false);
|
|
});
|
|
|
|
test(
|
|
'when a compiler cannot receive a shutdown request due to a connection error',
|
|
() async {
|
|
// When this occurs, the info file associated with the running compiler
|
|
// should be deleted, and the shutdown command should appear to have
|
|
// succeeded, because there's nothing actionable the user can do to fix
|
|
// the connection error.
|
|
p = project(mainSrc: 'void main() {}');
|
|
// Create a [serverInfoFile] with an invalid port to guarantee that a
|
|
// connection will not be established.
|
|
final serverInfoFile = path.join(p.dirPath, 'info');
|
|
File(serverInfoFile).writeAsStringSync('address:127.0.0.1 port:-12 ');
|
|
final result = await p.run([
|
|
'compilation-server',
|
|
'shutdown',
|
|
'--$residentCompilerInfoFileOption=$serverInfoFile',
|
|
]);
|
|
|
|
expect(result.stdout, matches(compilationServerShutdownRegExp));
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), false);
|
|
});
|
|
|
|
test('run and shutdown', () async {
|
|
p = project(mainSrc: 'void main() {}');
|
|
final serverInfoFile = path.join(p.dirPath, 'info');
|
|
final runResult = await p.run([
|
|
'run',
|
|
'--resident',
|
|
'--$residentCompilerInfoFileOption=$serverInfoFile',
|
|
p.relativeFilePath,
|
|
]);
|
|
|
|
expect(runResult.stdout, matches(compilationServerStartRegExp));
|
|
expect(runResult.stderr, isEmpty);
|
|
expect(runResult.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), true);
|
|
|
|
final result = await p.run([
|
|
'compilation-server',
|
|
'shutdown',
|
|
'--$residentCompilerInfoFileOption=$serverInfoFile',
|
|
]);
|
|
|
|
expect(result.stdout, matches(compilationServerShutdownRegExp));
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), false);
|
|
});
|
|
|
|
test('start and shutdown', () async {
|
|
p = project(mainSrc: 'void main() {}');
|
|
final serverInfoFile = path.join(p.dirPath, 'info');
|
|
final runResult = await p.run([
|
|
'compilation-server',
|
|
'start',
|
|
'--$residentCompilerInfoFileOption=$serverInfoFile',
|
|
]);
|
|
|
|
expect(runResult.stdout, matches(compilationServerStartRegExp));
|
|
expect(runResult.stderr, isEmpty);
|
|
expect(runResult.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), true);
|
|
|
|
final result = await p.run([
|
|
'compilation-server',
|
|
'shutdown',
|
|
'--$residentCompilerInfoFileOption=$serverInfoFile',
|
|
]);
|
|
|
|
expect(result.stdout, matches(compilationServerShutdownRegExp));
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), false);
|
|
});
|
|
|
|
test(
|
|
'start and shutdown when using legacy --resident-server-info-file option',
|
|
() async {
|
|
p = project(mainSrc: 'void main() {}');
|
|
final serverInfoFile = path.join(p.dirPath, 'info');
|
|
final runResult = await p.run([
|
|
'compilation-server',
|
|
'start',
|
|
'--resident-server-info-file=$serverInfoFile',
|
|
]);
|
|
|
|
expect(runResult.stdout, matches(compilationServerStartRegExp));
|
|
expect(runResult.stderr, isEmpty);
|
|
expect(runResult.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), true);
|
|
|
|
final result = await p.run([
|
|
'compilation-server',
|
|
'shutdown',
|
|
'--resident-server-info-file=$serverInfoFile',
|
|
]);
|
|
|
|
expect(result.stdout, matches(compilationServerShutdownRegExp));
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), false);
|
|
});
|
|
|
|
test(
|
|
'start and shutdown when passing a relative path to --resident-compiler-info-file',
|
|
() async {
|
|
p = project(mainSrc: 'void main() {}');
|
|
final serverInfoFile = path.join(p.dirPath, 'info');
|
|
final runResult = await p.run([
|
|
'compilation-server',
|
|
'start',
|
|
'--$residentCompilerInfoFileOption',
|
|
path.relative(serverInfoFile, from: p.dirPath),
|
|
]);
|
|
|
|
expect(runResult.stdout, matches(compilationServerStartRegExp));
|
|
expect(runResult.stderr, isEmpty);
|
|
expect(runResult.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), true);
|
|
|
|
final result = await p.run([
|
|
'compilation-server',
|
|
'shutdown',
|
|
'--$residentCompilerInfoFileOption',
|
|
path.relative(serverInfoFile, from: p.dirPath),
|
|
]);
|
|
|
|
expect(result.stdout, matches(compilationServerShutdownRegExp));
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.exitCode, 0);
|
|
expect(File(serverInfoFile).existsSync(), false);
|
|
});
|
|
}, timeout: longTimeout);
|
|
}
|