Refactor devicelab bin/run.dart and other cleanup (#96320)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_devicelab/framework/utils.dart' show rm;
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:process/process.dart';
|
||||
|
||||
@@ -20,6 +21,7 @@ void main() {
|
||||
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],
|
||||
]);
|
||||
@@ -87,9 +89,14 @@ void main() {
|
||||
|
||||
|
||||
test('runs A/B test', () async {
|
||||
final Directory tempDirectory = Directory.systemTemp.createTempSync('flutter_devicelab_ab_test.');
|
||||
final File abResultsFile = File(path.join(tempDirectory.path, 'test_results.json'));
|
||||
|
||||
expect(abResultsFile.existsSync(), isFalse);
|
||||
|
||||
final ProcessResult result = await runScript(
|
||||
<String>['smoke_test_success'],
|
||||
<String>['--ab=2', '--local-engine=host_debug_unopt'],
|
||||
<String>['--ab=2', '--local-engine=host_debug_unopt', '--ab-result-file', abResultsFile.path],
|
||||
);
|
||||
expect(result.exitCode, 0);
|
||||
|
||||
@@ -137,6 +144,9 @@ void main() {
|
||||
'metric2\t123.00 (0.00%)\t123.00 (0.00%)\t1.00x\t\n',
|
||||
),
|
||||
);
|
||||
|
||||
expect(abResultsFile.existsSync(), isTrue);
|
||||
rm(tempDirectory, recursive: true);
|
||||
});
|
||||
|
||||
test('fails to upload results to Cocoon if flags given', () async {
|
||||
|
||||
@@ -11,7 +11,6 @@ import 'common.dart';
|
||||
void main() {
|
||||
final Map<String, String> isolateParams = <String, String>{
|
||||
'runFlutterConfig': 'false',
|
||||
'runProcessCleanup': 'false',
|
||||
'timeoutInMinutes': '1',
|
||||
};
|
||||
List<String> printLog;
|
||||
@@ -27,7 +26,7 @@ void main() {
|
||||
logs: printLog,
|
||||
);
|
||||
expect(printLog.length, 2);
|
||||
expect(printLog[0], 'Total 1 executions: 1 success');
|
||||
expect(printLog[0], 'Test passed on first attempt.');
|
||||
expect(printLog[1], 'flaky: false');
|
||||
});
|
||||
|
||||
@@ -40,7 +39,7 @@ void main() {
|
||||
logs: printLog,
|
||||
);
|
||||
expect(printLog.length, 2);
|
||||
expect(printLog[0], 'Total 3 executions: 0 success');
|
||||
expect(printLog[0], 'Consistently failed across all 3 executions.');
|
||||
expect(printLog[1], 'flaky: false');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_devicelab/framework/running_processes.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
void main() {
|
||||
@@ -24,19 +30,19 @@ ProcessId CreationDate CommandLine
|
||||
results,
|
||||
equals(<RunningProcessInfo>[
|
||||
RunningProcessInfo(
|
||||
'6552',
|
||||
DateTime(2019, 7, 3, 17, 0, 27),
|
||||
6552,
|
||||
r'"C:\tools\dart-sdk\bin\dart.exe" .\bin\agent.dart ci',
|
||||
DateTime(2019, 7, 3, 17, 0, 27),
|
||||
),
|
||||
RunningProcessInfo(
|
||||
'6553',
|
||||
DateTime(2019, 7, 3, 22, 0, 27),
|
||||
6553,
|
||||
r'"C:\tools\dart-sdk1\bin\dart.exe" .\bin\agent.dart ci',
|
||||
DateTime(2019, 7, 3, 22, 0, 27),
|
||||
),
|
||||
RunningProcessInfo(
|
||||
'6554',
|
||||
DateTime(2019, 7, 3, 11, 0, 27),
|
||||
6554,
|
||||
r'"C:\tools\dart-sdk2\bin\dart.exe" .\bin\agent.dart ci',
|
||||
DateTime(2019, 7, 3, 11, 0, 27),
|
||||
),
|
||||
]));
|
||||
});
|
||||
@@ -55,15 +61,81 @@ Sat Mar 9 20:13:00 2019 49 /usr/sbin/syslogd
|
||||
results,
|
||||
equals(<RunningProcessInfo>[
|
||||
RunningProcessInfo(
|
||||
'1',
|
||||
DateTime(2019, 3, 9, 20, 12, 47),
|
||||
1,
|
||||
'/sbin/launchd',
|
||||
DateTime(2019, 3, 9, 20, 12, 47),
|
||||
),
|
||||
RunningProcessInfo(
|
||||
'49',
|
||||
DateTime(2019, 3, 9, 20, 13),
|
||||
49,
|
||||
'/usr/sbin/syslogd',
|
||||
DateTime(2019, 3, 9, 20, 13),
|
||||
),
|
||||
]));
|
||||
});
|
||||
|
||||
test('RunningProcessInfo.terminate', () {
|
||||
final RunningProcessInfo process = RunningProcessInfo(123, 'test', DateTime(456));
|
||||
final FakeProcessManager fakeProcessManager = FakeProcessManager();
|
||||
process.terminate(processManager: fakeProcessManager);
|
||||
if (Platform.isWindows) {
|
||||
expect(fakeProcessManager.log, <String>['run([taskkill.exe, /pid, 123, /f], null, null, null, null, null, null)']);
|
||||
} else {
|
||||
expect(fakeProcessManager.log, <String>['killPid(123, SIGKILL)']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class FakeProcessManager implements ProcessManager {
|
||||
final List<String> log = <String>[];
|
||||
|
||||
@override
|
||||
bool canRun(Object? a, { String? workingDirectory }) {
|
||||
log.add('canRun($a, $workingDirectory)');
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
bool killPid(int a, [ProcessSignal? b]) {
|
||||
log.add('killPid($a, $b)');
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProcessResult> run(List<Object> a, {
|
||||
Map<String, String>? environment,
|
||||
bool? includeParentEnvironment,
|
||||
bool? runInShell,
|
||||
Encoding? stderrEncoding,
|
||||
Encoding? stdoutEncoding,
|
||||
String? workingDirectory,
|
||||
}) async {
|
||||
log.add('run($a, $environment, $includeParentEnvironment, $runInShell, $stderrEncoding, $stdoutEncoding, $workingDirectory)');
|
||||
return ProcessResult(1, 0, 'stdout', 'stderr');
|
||||
}
|
||||
|
||||
@override
|
||||
ProcessResult runSync(List<Object> a, {
|
||||
Map<String, String>? environment,
|
||||
bool? includeParentEnvironment,
|
||||
bool? runInShell,
|
||||
Encoding? stderrEncoding,
|
||||
Encoding? stdoutEncoding,
|
||||
String? workingDirectory,
|
||||
}) {
|
||||
log.add('runSync($a, $environment, $includeParentEnvironment, $runInShell, $stderrEncoding, $stdoutEncoding, $workingDirectory)');
|
||||
return ProcessResult(1, 0, 'stdout', 'stderr');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Process> start(
|
||||
List<Object> a, {
|
||||
Map<String, String>? environment,
|
||||
bool? includeParentEnvironment,
|
||||
ProcessStartMode? mode,
|
||||
bool? runInShell,
|
||||
String? workingDirectory,
|
||||
}) {
|
||||
log.add('start($a, $environment, $includeParentEnvironment, $mode, $runInShell, $workingDirectory)');
|
||||
return Completer<Process>().future;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import '../common.dart';
|
||||
void main() {
|
||||
final Map<String, String> isolateParams = <String, String>{
|
||||
'runFlutterConfig': 'false',
|
||||
'runProcessCleanup': 'false',
|
||||
'timeoutInMinutes': '1',
|
||||
};
|
||||
|
||||
@@ -66,7 +65,7 @@ void main() {
|
||||
final String capturedPrint = capturedPrintLines.toString();
|
||||
expect(capturedPrint,
|
||||
contains('with environment {FLUTTER_DEVICELAB_DEVICEID: FAKE_SUCCESS, BOT: true, LANG: en_US.UTF-8}'));
|
||||
expect(capturedPrint, contains('exit code: 0'));
|
||||
expect(capturedPrint, contains('Process terminated with exit code 0.'));
|
||||
});
|
||||
|
||||
test('throws exception when build and test arg are given', () async {
|
||||
|
||||
@@ -36,8 +36,8 @@ void main() {
|
||||
|
||||
group('engine environment declarations', () {
|
||||
test('localEngine', () {
|
||||
expect(localEngine, null);
|
||||
expect(localEngineSrcPath, null);
|
||||
expect(localEngineFromEnv, null);
|
||||
expect(localEngineSrcPathFromEnv, null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user