forked from firka/flutter
Simplify devicelab logic and fix tests (#139122)
- fix https://github.com/flutter/flutter/issues/53707 by having the test not expect a timeout but instead actually look for the retry message - simplify the `--task` option to only accept task names rather than also accepting paths - remove some obsolete options that referred to the manifest which no longer seems to exist
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_devicelab/framework/utils.dart' show rm;
|
||||
@@ -12,45 +13,54 @@ import 'common.dart';
|
||||
|
||||
void main() {
|
||||
const ProcessManager processManager = LocalProcessManager();
|
||||
final String dart = path.absolute(
|
||||
path.join('..', '..', 'bin', 'cache', 'dart-sdk', 'bin', 'dart'));
|
||||
|
||||
group('run.dart script', () {
|
||||
Future<ProcessResult> runScript(List<String> testNames,
|
||||
// The tasks here refer to files in ../bin/tasks/*.dart
|
||||
|
||||
Future<ProcessResult> runScript(List<String> taskNames,
|
||||
[List<String> otherArgs = const <String>[]]) async {
|
||||
final String dart = path.absolute(
|
||||
path.join('..', '..', 'bin', 'cache', 'dart-sdk', 'bin', 'dart'));
|
||||
final ProcessResult scriptProcess = processManager.runSync(<String>[
|
||||
dart,
|
||||
'bin/run.dart',
|
||||
'--no-terminate-stray-dart-processes',
|
||||
...otherArgs,
|
||||
for (final String testName in testNames) ...<String>['-t', testName],
|
||||
for (final String testName in taskNames) ...<String>['-t', testName],
|
||||
]);
|
||||
return scriptProcess;
|
||||
}
|
||||
|
||||
Future<void> expectScriptResult(
|
||||
List<String> testNames,
|
||||
List<String> taskNames,
|
||||
int expectedExitCode,
|
||||
{String? deviceId}
|
||||
) async {
|
||||
final ProcessResult result = await runScript(testNames, <String>[
|
||||
final ProcessResult result = await runScript(taskNames, <String>[
|
||||
if (deviceId != null) ...<String>['-d', deviceId],
|
||||
]);
|
||||
expect(result.exitCode, expectedExitCode,
|
||||
reason:
|
||||
'[ stderr from test process ]\n\n${result.stderr}\n\n[ end of stderr ]'
|
||||
'\n\n[ stdout from test process ]\n\n${result.stdout}\n\n[ end of stdout ]');
|
||||
expect(
|
||||
result.exitCode,
|
||||
expectedExitCode,
|
||||
reason:
|
||||
'[ stderr from test process ]\n'
|
||||
'\n'
|
||||
'${result.stderr}\n'
|
||||
'\n'
|
||||
'[ end of stderr ]\n'
|
||||
'\n'
|
||||
'[ stdout from test process ]\n'
|
||||
'\n'
|
||||
'${result.stdout}\n'
|
||||
'\n'
|
||||
'[ end of stdout ]',
|
||||
);
|
||||
}
|
||||
|
||||
test('exits with code 0 when succeeds', () async {
|
||||
await expectScriptResult(<String>['smoke_test_success'], 0);
|
||||
});
|
||||
|
||||
test('accepts file paths', () async {
|
||||
await expectScriptResult(
|
||||
<String>['bin/tasks/smoke_test_success.dart'], 0);
|
||||
});
|
||||
|
||||
test('rejects invalid file paths', () async {
|
||||
await expectScriptResult(<String>['lib/framework/adb.dart'], 1);
|
||||
});
|
||||
@@ -63,9 +73,18 @@ void main() {
|
||||
await expectScriptResult(<String>['smoke_test_failure'], 1);
|
||||
});
|
||||
|
||||
test('exits with code 1 when fails to connect', () async {
|
||||
await expectScriptResult(<String>['smoke_test_setup_failure'], 1);
|
||||
}, skip: true); // https://github.com/flutter/flutter/issues/53707
|
||||
test('prints a message after a few seconds when failing to connect (this test takes >10s)', () async {
|
||||
final Process process = await processManager.start(<String>[
|
||||
dart,
|
||||
'bin/run.dart',
|
||||
'--no-terminate-stray-dart-processes',
|
||||
'-t', 'smoke_test_setup_failure',
|
||||
]);
|
||||
await process.stdout.transform(utf8.decoder).where(
|
||||
(String line) => line.contains('VM service still not ready. It is possible the target has failed')
|
||||
).first;
|
||||
expect(process.kill(), isTrue);
|
||||
});
|
||||
|
||||
test('exits with code 1 when results are mixed', () async {
|
||||
await expectScriptResult(
|
||||
|
||||
Reference in New Issue
Block a user