test(ci): run generated code verification without widget contention
Gitea CI / Check code and tests (pull_request) Successful in 14m15s
Gitea CI / Build Windows x64 app (pull_request) Successful in 4m19s
Gitea CI / Gitea CI passed (pull_request) Successful in 1s
Gitea CI / Build Android APK (pull_request) Successful in 5m25s
Gitea CI / Audit and package Windows x64 (pull_request) Successful in 1m39s
Gitea CI / Assemble and validate CI artifacts (pull_request) Successful in 57s
Gitea CI / Check code and tests (pull_request) Successful in 14m15s
Gitea CI / Build Windows x64 app (pull_request) Successful in 4m19s
Gitea CI / Gitea CI passed (pull_request) Successful in 1s
Gitea CI / Build Android APK (pull_request) Successful in 5m25s
Gitea CI / Audit and package Windows x64 (pull_request) Successful in 1m39s
Gitea CI / Assemble and validate CI artifacts (pull_request) Successful in 57s
This commit is contained in:
1 parent
3022b3a5e2
commit
8dada4726c
2 files changed
+80
-20
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
@@ -14,29 +15,83 @@ const _generatedFiles = [
|
||||
];
|
||||
|
||||
void main() {
|
||||
test('workspace generated code is up to date', () async {
|
||||
await _expectNoUntrackedGeneratedFiles();
|
||||
final before = await _generatedContents();
|
||||
final dart = flutterTestDartExecutable();
|
||||
for (final directory in _generatorRoots()) {
|
||||
final result = await Process.run(dart, [
|
||||
'run',
|
||||
'build_runner',
|
||||
'build',
|
||||
], workingDirectory: directory);
|
||||
test(
|
||||
'workspace generated code is up to date',
|
||||
() async {
|
||||
await _expectNoUntrackedGeneratedFiles();
|
||||
final before = await _generatedContents();
|
||||
final dart = flutterTestDartExecutable();
|
||||
final elapsed = Stopwatch()..start();
|
||||
for (final directory in _generatorRoots()) {
|
||||
await _generate(
|
||||
dart,
|
||||
directory,
|
||||
const Duration(minutes: 5) -
|
||||
const Duration(seconds: 10) -
|
||||
elapsed.elapsed,
|
||||
);
|
||||
}
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: '$directory\n${result.stdout}\n${result.stderr}',
|
||||
await _generatedContents(),
|
||||
before,
|
||||
reason: 'Generated files changed. Run dart run build_runner build and review the output.',
|
||||
);
|
||||
await _expectNoUntrackedGeneratedFiles();
|
||||
},
|
||||
timeout: const Timeout(Duration(minutes: 5)),
|
||||
tags: ['codegen'],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _generate(
|
||||
String dart,
|
||||
String directory,
|
||||
Duration remaining,
|
||||
) async {
|
||||
if (remaining <= Duration.zero) {
|
||||
throw TimeoutException('Generated-code verification budget exhausted');
|
||||
}
|
||||
final elapsed = Stopwatch()..start();
|
||||
stdout.writeln(
|
||||
'Generating $directory; remaining budget: ${remaining.inSeconds}s',
|
||||
);
|
||||
final process = await Process.start(dart, [
|
||||
'run',
|
||||
'build_runner',
|
||||
'build',
|
||||
], workingDirectory: directory);
|
||||
final output = StringBuffer();
|
||||
Future<void> read(Stream<List<int>> stream) async {
|
||||
await for (final line
|
||||
in stream.transform(utf8.decoder).transform(const LineSplitter())) {
|
||||
output.writeln(line);
|
||||
stdout.writeln('[$directory] $line');
|
||||
}
|
||||
expect(
|
||||
await _generatedContents(),
|
||||
before,
|
||||
reason: 'Generated files changed. Run dart run build_runner build and review the output.',
|
||||
}
|
||||
|
||||
final streams = Future.wait([read(process.stdout), read(process.stderr)]);
|
||||
var exited = false;
|
||||
try {
|
||||
final exitCode = await process.exitCode.timeout(remaining);
|
||||
exited = true;
|
||||
await streams;
|
||||
expect(exitCode, 0, reason: '$directory\n$output');
|
||||
} finally {
|
||||
if (!exited) {
|
||||
// Flutter's outer test timeout cannot terminate Process.run children.
|
||||
// End the generator before leaving the test, including on Windows.
|
||||
if (Platform.isWindows) {
|
||||
await Process.run('taskkill', ['/PID', '${process.pid}', '/T', '/F']);
|
||||
} else {
|
||||
process.kill(ProcessSignal.sigkill);
|
||||
}
|
||||
await process.exitCode;
|
||||
await streams;
|
||||
}
|
||||
stdout.writeln(
|
||||
'Generation $directory ended after ${elapsed.elapsed.inMilliseconds}ms',
|
||||
);
|
||||
await _expectNoUntrackedGeneratedFiles();
|
||||
}, timeout: const Timeout(Duration(minutes: 5)));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _expectNoUntrackedGeneratedFiles() async {
|
||||
|
||||
+6
-1
@@ -45,7 +45,12 @@ def check_analyze():
|
||||
def check_flutter():
|
||||
package_tests = sorted(str(path.relative_to(ROOT)) for pattern in ('*/test', '*/example/test')
|
||||
for path in (ROOT / 'packages').glob(pattern))
|
||||
run(tool_command('flutter', ['test', '--reporter', 'expanded', 'test', *package_tests]))
|
||||
run(tool_command('flutter', ['test', '--reporter', 'expanded', '--exclude-tags', 'codegen',
|
||||
'test', *package_tests]))
|
||||
# build_runner compiles generators and performs repository-wide file I/O.
|
||||
# Keep this gate serial with widget tests to avoid competing with their isolates.
|
||||
run(tool_command('flutter', ['test', '--reporter', 'expanded', '--tags', 'codegen',
|
||||
'test/generated_code_test.dart']))
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in new issue
Block a user