Devicelab tests (Chrome run, Web compile) for New Flutter Gallery (#53096)

This commit is contained in:
Tianguang
2020-04-21 20:48:03 +02:00
committed by GitHub
parent d8f353af5b
commit fbf4fa0a05
5 changed files with 247 additions and 47 deletions

View File

@@ -0,0 +1,112 @@
// Copyright 2014 The Flutter Authors. 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:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart';
Future<void> main() async {
await task(const NewGalleryChromeRunTest().run);
}
/// URI for the New Flutter Gallery repository.
const String galleryRepo = 'https://github.com/flutter/gallery.git';
/// After the gallery loads, a duration of [durationToWaitForError]
/// is waited, allowing any possible exceptions to be thrown.
const Duration durationToWaitForError = Duration(seconds: 5);
/// Flutter prints this string when an app is successfully loaded.
/// Used to check when the app is successfully loaded.
const String successfullyLoadedString = 'To hot restart';
/// Flutter prints this string when an exception is caught.
/// Used to check if there are any exceptions.
const String exceptionString = 'EXCEPTION CAUGHT';
/// Checks that the New Flutter Gallery runs successfully on Chrome.
class NewGalleryChromeRunTest {
const NewGalleryChromeRunTest();
/// Runs the test.
Future<TaskResult> run() async {
await gitClone(path: 'temp', repo: galleryRepo);
final TaskResult result = await inDirectory<TaskResult>('temp/gallery', () async {
await flutter('doctor');
await flutter('packages', options: <String>['get']);
await flutter('build', options: <String>[
'web',
'-v',
'--release',
'--no-pub',
], environment: <String, String>{
'FLUTTER_WEB': 'true',
});
final List<String> options = <String>['-d', 'chrome', '--verbose', '--resident'];
final Process process = await startProcess(
'flutter',
flutterCommandArgs('run', options),
environment: <String, String>{
'FLUTTER_WEB': 'true',
},
);
final Completer<void> stdoutDone = Completer<void>();
final Completer<void> stderrDone = Completer<void>();
bool success = true;
process.stdout
.transform<String>(utf8.decoder)
.transform<String>(const LineSplitter())
.listen((String line) {
if (line.contains(successfullyLoadedString)) {
// Successfully started.
Future<void>.delayed(
durationToWaitForError,
() {process.stdin.write('q');}
);
}
if (line.contains(exceptionString)) {
success = false;
}
print('stdout: $line');
}, onDone: () {
stdoutDone.complete();
});
process.stderr
.transform<String>(utf8.decoder)
.transform<String>(const LineSplitter())
.listen((String line) {
print('stderr: $line');
}, onDone: () {
stderrDone.complete();
});
await Future.wait<void>(<Future<void>>[
stdoutDone.future,
stderrDone.future,
]);
await process.exitCode;
if (success) {
return TaskResult.success(<String, dynamic>{});
} else {
return TaskResult.failure('An exception was thrown.');
}
});
rmTree(Directory('temp'));
return result;
}
}

View File

@@ -0,0 +1,44 @@
// Copyright 2014 The Flutter Authors. 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:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:flutter_devicelab/tasks/perf_tests.dart' show WebCompileTest;
Future<void> main() async {
await task(const NewGalleryWebCompileTest().run);
}
/// Measures the time to compile the New Flutter Gallery to JavaScript
/// and the size of the compiled code.
class NewGalleryWebCompileTest {
const NewGalleryWebCompileTest();
String get metricKeyPrefix => 'new_gallery';
/// Runs the test.
Future<TaskResult> run() async {
await gitClone(path: 'temp', repo: 'https://github.com/flutter/gallery.git');
final Map<String, Object> metrics = await inDirectory<Map<String, int>>(
'temp/gallery',
() async {
await flutter('doctor');
return await WebCompileTest.runSingleBuildTest(
directory: 'temp/gallery',
metric: metricKeyPrefix,
measureBuildTime: true,
);
},
);
rmTree(Directory('temp'));
return TaskResult.success(metrics, benchmarkScoreKeys: metrics.keys.toList());
}
}